unity3d C# 关于随机点产生随机物体问题。
voidStart(){p1=newVector3(-2.5f,0.8f,-0.01f);p2=newVector3(-2.5f,0.4f,-0.01f);p3=newV...
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)产生。
而且物体是翻转的。
谢谢大家! 展开
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)产生。
而且物体是翻转的。
谢谢大家! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询