这个问题有点难以解释,也许令人困惑,但我会尽力解释。我在游戏中使用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));
}
}
它看起来如何:
当玩家与立方体碰撞时,它将成为它的一个孩子,直到它从立方体上跳下来。 当玩家成为玩家的孩子时,立方体会停止移动,几秒钟后它会再次开始移动,为什么?