最近,我正在制作一个国际象棋游戏,其中国际象棋移动时有动画。我使用了两种方法,RotateTowards和Translate()。 RotateTowards()只能在Update()函数中运行。这里是我的代码:如何在Update()函数完成后停止方法? - C# - Unity3D
using UnityEngine;
using System.Collections;
public class OnTouch : MonoBehaviour {
public GameObject cube;
public GameObject sphere;
int clicked;
Quaternion lastRot;
// Use this for initialization
void Start() {
clicked = 0;
}
// Update is called once per frame
void Update() {
if(clicked == 1)
{
var rotation = Quaternion.LookRotation(cube.transform.position - transform.position);
print(rotation);
rotation.x = 0;
rotation.z = 0;
cube.transform.rotation = Quaternion.RotateTowards(cube.transform.rotation, rotation, 100 * Time.deltaTime);
if(cube.transform.rotation = ???? <- No Idea){
clicked = 0;
}
}
}
void OnMouseDown()
{
print("clicked");
clicked = 1;
}
}
我将该代码附加到所有国际象棋瓷砖。所以,立方体停止旋转后,我试图点击另一个瓷砖。但是,之前的RotateTowards()方法仍在运行,所以它同时运行。我试图做IF逻辑,但我不知道
if(cube.transform.rotation == ??? <-- No idea){
clicked = 0;
}
任何解决方案?谢谢!
您可以考虑尝试如LeanTween它是Asset Store上可用的免费资产。这是简单而强大的工具。有了这个assset,从点到点的翻译变得更容易,因为不需要在Update()中调用它。 –
@marecki BTw,谢谢。我会在稍后找到它。 – Sena