我已经完成了精灵动画(行走,站立,攻击)现在我遇到问题,当我按下某些按钮时,弄清楚如何让角色移动和攻击。
这是我尝试的脚本。
using System.Collections;
public class PlayerMovement : MonoBehaviour {
Rigidbody2D rbody;
Animator anim;
// Use this for initialization
void Start () {
rbody = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
Vector2 movement_vector = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
if (movement_vector != Vector2.zero) {
anim.SetBool("iswalking", true);
anim.SetFloat("Input_x"), movement_vector.x);
anim.SetFloat("Input_y"), movement_vector.y);
}
else {
anim.SetBool( "iswalking", false);
}
rbody.MovePosition(rbody.position + movement_vector * Time.deltaTime);
}
}