【发布时间】:2023-01-02 20:10:55
【问题描述】:
我基本上想让一个游戏对象在到达空间中的某个位置后转身。我有一个预制件,创建游戏对象并使其随机移动。但是,打印位置值给我相同的值 (0,4,0),这基本上是产卵者的位置。我想要物体在空间中移动时的位置。这是代码:
If (Input.GetMouseButtonDown(0))
{
direction = new Vector3(Random.Range(-1.0f,1.0f), Random.Range(-1.0f,1.0f), Random.Range(-1.0f,1.0f));
GameObject sphere = Instantiate(spherePrefab, transform.position, Quaternion.identity);
sphere.GetComponent<Rigidbody>().velocity = direction * speed; // this moves the object randomly
position = sphere.transform.position;
Debug.Log(position); // This prints the spawners location every frame but no the spheres.
我只在场景中创建了一个生成器对象,并用我的脚本实例化了球体。
任何帮助表示赞赏!
【问题讨论】: