unity3d关于随机点产生物体的问题。

public List<GameObject>_yu;
public List<Vector3>_point;
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 () {
AddDians();
CreateFish();
}
void AddDian(Vector3 dian){
_point.Add(dian);
}
void AddDians(){
AddDian(p1);
AddDian(p2);
AddDian(p3);
AddDian(p4);
AddDian(p5);
AddDian(p6);
AddDian(p7);
AddDian(p8);
AddDian(p9);
AddDian(p10);
}
void CreateFish(){
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"));
}
会出现物体从(0,0,0)产生的问题,而且物体会翻转。
求帮助。
谢谢。
最新回答
雨中的狗尾巴草

2024-10-15 07:53:58

翻转是因为你都用了一个旋转度Quaternion.identity,这个地方要改为你需要的角度

至于位置_point[Random.Range(0,5)],你在初始化之前输出一下,看为什么是000
追问
Quaternion.identity
这个地方怎么改需要的角度?
追答
这是个四元数,代表的是transform.rotation,如果你不知道你想要的角度是多少Quaternion,就先调好角度,找个代码输出一下(transform.rotation),在控制台复制输出的四元数,再写入代码中,采纳吧...