0

这个问题有点难以解释,也可能令人困惑,但我会尽力解释它。我在游戏中使用 iTween 来移动立方体。当玩家与激活立方体碰撞时/是激活立方体的一个孩子,立方体开始移动。但是,当我的玩家跳到一个移动的立方体上时,立方体会停止移动几秒钟,我不知道为什么。它与 iTween.MoveTo 有关,因为在使用 iTween.MoveBy 时不会发生这种情况(就像我在下面脚本中的 Cube (1) 2 中所做的那样),但我必须使用 MoveTo。

脚本:

using UnityEngine;
using System.Collections;

public class CubeMovement: MonoBehaviour
{   

public int startX; 
public float startTime;
public int pingPongX;
public float pingPongTime;
private bool started;
public GameObject playerObj;
public float originalY;
public float fallDownTime = 1912;

public GameObject activatingCube;

void Awake()
{
    pingPongTime = (startTime / (Mathf.Abs(gameObject.transform.position.x - startX))) * (startX - pingPongX);
}

void Update() 
{
    Player player = playerObj.GetComponent<Player> ();
    //All blocks start moving after 1 click
    //if (player.clicks == 1 && started == false) 
    //{
    //  StartX ();
    //}
    Debug.Log(started);
    //This block starts moving after player collides with activatingCube
    if (started == false && playerObj.transform.parent == activatingCube.transform) 
    {
        StartX ();
        started = true;
        Debug.Log ("Going to start");
    }
}

void StartX()
{
    started = true;
    Debug.Log ("Started");
    if (gameObject.transform.name == "Cube (1)2") //omdat dit blokje hetzelfde is als activating cube werkte het alleen met moveby
    {
        iTween.MoveBy (gameObject, iTween.Hash ("x", startX, "time", startTime, "easeType", "easeInOutSine", "loopType", "none", "delay", 0));
    }
    StartCoroutine(FallDown(fallDownTime));
    StartCoroutine (StartPingPong (startTime));
    if (gameObject.transform.name != "Cube (1)2") 
    {
        iTween.MoveTo (gameObject, iTween.Hash ("x", startX, "time", startTime, "easeType", "easeInOutSine", "loopType", "none", "delay", 0));
    }
}




IEnumerator StartPingPong(float startTime)
{
    yield return new WaitForSeconds (startTime);
    iTween.MoveTo(gameObject, iTween.Hash("x", pingPongX, "time", pingPongTime, "easeType", "easeInOutSine", "loopType", "pingPong", "delay", 0));
}
}

它的样子:

https://i.stack.imgur.com/vGkaV.gif

顺便说一句,当玩家与一个立方体碰撞时,它将成为它的一个孩子,直到它从立方体上跳下来。当玩家成为它的孩子时,立方体停止移动,几秒钟后它又开始移动,为什么?

4

0 回答 0