人物 rigbody
脚本
private Rigidbody2D rb;
private Animator anim;
public float speed;
private Vector2 movevelocity;
// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
Vector2 moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), 0);
movevelocity = moveInput * speed;
if(moveInput !=Vector2.zero)
{
anim.SetBool("walk", true);
}
}
private void FixedUpdate()//让刚体移动
{
rb.MovePosition(rb.position + movevelocity * Time.fixedDeltaTime);
}
再人物的animator内增加 bool