如何使用Vector3.MoveToward()制作PianoTiles Type Game Unity

时间:2017-03-27 11:04:13

标签: unity3d 2d game-physics translate-animation

我正在努力制作一个钢琴瓷砖式游戏。所以我有6个空的游戏对象(targetGrid [0-5]),它们是我的图块的目标。我将第一个瓷砖发送到第一个目标[0],到达targetGrid [0]后我将新目标发送到targetGrid 1,依此类推。

但问题是我的tile的速度比targetGrid [0] -targetGrid 1的速度慢于其他像:

speedOf targetGrid[1-2]
= speedOf targetGrid[2-3]
= speedOf targetGrid[3-4]
= speedOf targetGrid[4-5]
>>> speedOf targetGrid[0-1]

这是一个问题视频: https://www.youtube.com/watch?v=20pwdbaw0aQ

看,一开始心脏很慢。然后它变得更快。

为什么?我怎样才能解决这个问题。

这是我的代码和screenShot:

public class CollectiblesMovement : MonoBehaviour {

    public List<Transform> gridPos = new List<Transform> ();

    //public bool middleCrossed = false;

    //public CollectableTypes collectableTypes;

    public CollectibleManager collectableManager;
    private int currentGridNo = 0;

    // Use this for initialization
    void Start () {
        transform.position = new Vector3 (gridPos[0].position.x,gridPos[0].position.y);
    }

    // Update is called once per frame
    void Update () {
        if(currentGridNo<5)
        transform.position = Vector3.MoveTowards (transform.position, gridPos [currentGridNo+1].position, collectableManager.collectable_speed*Time.deltaTime);
        if (transform.position == gridPos [Mathf.Clamp((currentGridNo+1),0,5)].position) {
            if (currentGridNo < 5) {
                Debug.Log ("calling " + currentGridNo + " Grid");
                MakeNextObjectGo ();
            }
            else {
                Debug.Log ("calling ManagerFunction");
                currentGridNo = 0;
                transform.position = new Vector3 (gridPos[currentGridNo].position.x, gridPos[currentGridNo].position.y);
            }
        }
    }

    public void MakeNextObjectGo()
    {
        currentGridNo++;
        collectableManager.WhichGridCrossedGridCrossed (transform);
    }

    public void StartAgain()
    {
        collectableManager.FinishedMoving (transform);
    }
}

看到网格中的移动速度不一样。

0 个答案:

没有答案