我想创建用于移动到左右2D动画的按钮(两个按钮:向左按钮和向右按钮)
我的c#脚本是:
private bool moveLeft;
private bool moveRight;
Animator animator;
float forwardSpeed = 10f;
// Use this for initialization
void Start () {
animator = this.GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if (moveLeft == true) {
this.GetComponent<Rigidbody2D> ().AddForce (Vector2.left * forwardSpeed);
animator.SetInteger ("Direction", 2);
}
if (moveLeft == false) {
this.GetComponent<Rigidbody2D> ().AddForce (Vector2.right * forwardSpeed);
animator.SetInteger ("Direction", 4);
}
}
public void MoveMeLeft()
{
moveLeft = true;
}
public void StopMeLeft ()
{
moveLeft = false;
}
}
*
所以它会执行事件触发器,所以指针向下,但指针启动时不要返回指针....
答案 0 :(得分:-2)
任何物理代码都必须用FixedUpdate
函数而不是Update