【问题标题】:Why when moving objects forward they are moving very slow ? How can i change the speed?为什么向前移动物体时它们移动得非常慢?我怎样才能改变速度?
【发布时间】:2016-10-06 07:19:33
【问题描述】:

Update 函数中: UpdateSpheres 创建对象然后移动它们,但是它们移动得很慢。

private void Update()
{
    UpdateSpheres();
    MoveShips();
}

private void MoveShips()
{
    var spheres = GameObject.FindGameObjectsWithTag("MySphere");
    foreach (Transform child in spheres[0].transform) 
    {
        child.transform.position += Vector3.forward * Time.deltaTime;
    }
}

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    在每一帧中调用FindGameObjectsWithTag 非常慢。在 Start 函数中调用一次。还添加一个公共速度变量,您可以使用多个变量来更改速度。您可以从编辑器中修改此速度变量,直到获得所需的速度。请务必查看脚本的其余部分,并确保您没有在 Update 函数中使用 GameObject.FindFindGameObjectsWithTag 或类似函数。

    GameObject[] spheres;
    public float moveSpeed = 50;
    
    void Start()
    {
        spheres = GameObject.FindGameObjectsWithTag("MySphere");
    }
    
    private void Update()
    {
        UpdateSpheres();
        MoveShips();
    }
    
    private void MoveShips()
    {
        foreach (Transform child in spheres[0].transform)
        {
            child.transform.position += Vector3.forward * Time.deltaTime * moveSpeed;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-14
      • 1970-01-01
      • 1970-01-01
      • 2011-04-22
      • 2010-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多