unity3d C# 关于随机点产生随机物体问题.void Start () {p1 = new Vector3 (-2.5f,0.8f,-0.01f);p2 = new Vector3 (-2.5f,0.4f,-0.01f);p3 = new Vector3 (-2.5f,-0f,-0.01f);p4 = new Vector3 (-2.5f,-0.4f,-0.01f);p5 = new Vector3 (-2.5f,-0.8f,-0.01f
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/25 17:54:58
unity3d C# 关于随机点产生随机物体问题.void Start () {p1 = new Vector3 (-2.5f,0.8f,-0.01f);p2 = new Vector3 (-2.5f,0.4f,-0.01f);p3 = new Vector3 (-2.5f,-0f,-0.01f);p4 = new Vector3 (-2.5f,-0.4f,-0.01f);p5 = new Vector3 (-2.5f,-0.8f,-0.01f
unity3d C# 关于随机点产生随机物体问题.
void Start () {
p1 = new Vector3 (-2.5f,0.8f,-0.01f);
p2 = new Vector3 (-2.5f,0.4f,-0.01f);
p3 = new Vector3 (-2.5f,-0f,-0.01f);
p4 = new Vector3 (-2.5f,-0.4f,-0.01f);
p5 = new Vector3 (-2.5f,-0.8f,-0.01f);
p6 = new Vector3 (2.5f,0.8f,-0.01f);
p7 = new Vector3 (2.5f,0.4f,-0.01f);
p8 = new Vector3 (2.5f,0f,-0.01f);
p9 = new Vector3 (2.5f,-0.4f,-0.01f);
p10 = new Vector3 (2.5f,-0.8f,-0.01f);
}
void Update () {
i = Random.Range(1,6);
AddDians();
CreateFish();
CreateFish2();
CreateFish3();
CreateFish4();
CreateFish5();
void CreateFish(){
if(i == 1){
GameObject yu = (GameObject) Instantiate(_yu[Random.Range(0,5)],_point[Random.Range(0,5)],Quaternion.identity);
GameObject yu2 = (GameObject)Instantiate(_yu[Random.Range(6,_yu.Count)],_point[Random.Range(6,_point.Count)],Quaternion.identity);
iTween.MoveTo(yu,iTween.Hash("x",2.5,"time",4,"EaseType","Linear"));
iTween.MoveTo(yu2,iTween.Hash("x",-2.5,"time",4,"EaseType","Linear"));
}
}
void CreateFish2(){
if(i == 2){
GameObject yu = (GameObject)Instantiate(_yu[Random.Range(0,5)],_point[Random.Range(0,5)],Quaternion.identity);
GameObject yu2 = (GameObject)Instantiate(_yu[Random.Range(6,_yu.Count)],_point[Random.Range(6,_point.Count)],Quaternion.identity);
iTween.MoveTo(yu,iTween.Hash("x",2.5,"time",4,"EaseType","Linear"));
iTween.MoveTo(yu2,iTween.Hash("x",-2.5,"time",4,"EaseType","Linear"));
}
}
void CreateFish3(){
if(i == 3){
GameObject yu = (GameObject)Instantiate(_yu[Random.Range(0,5)],_point[Random.Range(0,5)],Quaternion.identity);
GameObject yu2 = (GameObject)Instantiate(_yu[Random.Range(6,_yu.Count)],_point[Random.Range(6,_point.Count)],Quaternion.identity);
iTween.MoveTo(yu,iTween.Hash("x",2.5,"time",4,"EaseType","Linear"));
iTween.MoveTo(yu2,iTween.Hash("x",-2.5,"time",4,"EaseType","Linear"));
curTime = 0;
}
}
void CreateFish4(){
if(i == 4){
GameObject yu = (GameObject)Instantiate(_yu[Random.Range(0,5)],_point[Random.Range(0,5)],Quaternion.identity);
GameObject yu2 = (GameObject)Instantiate(_yu[Random.Range(6,_yu.Count)],_point[Random.Range(6,_point.Count)],Quaternion.identity);
iTween.MoveTo(yu,iTween.Hash("x",2.5,"time",4,"EaseType","Linear"));
iTween.MoveTo(yu2,iTween.Hash("x",-2.5,"time",4,"EaseType","Linear"));
}
}
void CreateFish5(){
if(i == 5){
GameObject yu = (GameObject)Instantiate(_yu[Random.Range(0,5)],_point[Random.Range(0,5)],Quaternion.identity);
GameObject yu2 = (GameObject)Instantiate(_yu[Random.Range(6,_yu.Count)],_point[Random.Range(6,_point.Count)],Quaternion.identity);
iTween.MoveTo(yu,iTween.Hash("x",2.5,"time",4,"EaseType","Linear"));
iTween.MoveTo(yu2,iTween.Hash("x",-2.5,"time",4,"EaseType","Linear"));
}
}
关于创建yu和yu2,是因为物体需要从两个方向过来,所以左面的物体从左面产生,右面的物体从右面产生.
现在的问题是,有一部分的物体从(0,0,0)产生.
而且物体是翻转的.
unity3d C# 关于随机点产生随机物体问题.void Start () {p1 = new Vector3 (-2.5f,0.8f,-0.01f);p2 = new Vector3 (-2.5f,0.4f,-0.01f);p3 = new Vector3 (-2.5f,-0f,-0.01f);p4 = new Vector3 (-2.5f,-0.4f,-0.01f);p5 = new Vector3 (-2.5f,-0.8f,-0.01f
为什么你提问了两个同样的问题...难道是为了再采纳我一次?- -!