56 lines
1.2 KiB
C#
56 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEditorInternal;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class PacMan : MonoBehaviour
|
|
{
|
|
public PacManInput pacManInputControl;//输入系统
|
|
|
|
public Rigidbody2D rb;
|
|
public Animator animator;
|
|
|
|
public Vector2 inputDirection;//输入方向的数值
|
|
public float speed;//速度
|
|
|
|
private void Awake()
|
|
{
|
|
pacManInputControl = new PacManInput();//new一个新的输入系统
|
|
rb = GetComponent<Rigidbody2D>();
|
|
animator = GetComponent<Animator>();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
pacManInputControl.Enable();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
pacManInputControl.Disable();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
inputDirection = pacManInputControl.PacManInputSystem.Move.ReadValue<Vector2>();//读取数值
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
Move();
|
|
PacManAnimation();
|
|
}
|
|
|
|
public void Move()
|
|
{
|
|
rb.velocity = new Vector2(inputDirection.x * speed * Time.deltaTime, inputDirection.y * speed * Time.deltaTime);
|
|
}
|
|
|
|
public void PacManAnimation()
|
|
{
|
|
animator.SetFloat("H",inputDirection.x);
|
|
animator.SetFloat("V", inputDirection.y);
|
|
}
|
|
}
|