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;//<2F><><EFBFBD><EFBFBD>ϵͳ
|
|||
|
|
|||
|
public Rigidbody2D rb;
|
|||
|
public Animator animator;
|
|||
|
|
|||
|
public Vector2 inputDirection;//<2F><><EFBFBD>뷽<EFBFBD><EBB7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|||
|
public float speed;//<2F>ٶ<EFBFBD>
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
pacManInputControl = new PacManInput();//newһ<77><D2BB><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>ϵͳ
|
|||
|
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>();//<2F><>ȡ<EFBFBD><C8A1>ֵ
|
|||
|
}
|
|||
|
|
|||
|
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);
|
|||
|
}
|
|||
|
}
|