42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
![]() |
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.InputSystem;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 玩家类,代表屏幕外的玩家,用来处理输入、传达信息、记录状态
|
||
|
/// </summary>
|
||
|
public class Player : MonoBehaviour
|
||
|
{
|
||
|
private PlayerC playerC;
|
||
|
private Horse horse;
|
||
|
|
||
|
void Start()
|
||
|
{
|
||
|
//找到必要的物体和组件
|
||
|
FindSth();
|
||
|
//绑定输入
|
||
|
InputBinding();
|
||
|
}
|
||
|
|
||
|
private void FindSth()
|
||
|
{
|
||
|
try{
|
||
|
horse = transform.Find("马").GetComponent<Horse>();
|
||
|
}catch(System.Exception) {Debug.LogError("要么子物体中没有马、要么马的名字不是马、要么马身上没有Horse组件");}
|
||
|
|
||
|
}
|
||
|
|
||
|
private void InputBinding()
|
||
|
{
|
||
|
playerC = new PlayerC();
|
||
|
playerC.GamePlay.MoveFrontFoot.performed += ctx => horse.SetInputFrontVector(ctx.ReadValue<Vector2>());
|
||
|
playerC.GamePlay.MoveBackFoot.performed += ctx => horse.SetInputBackVector(ctx.ReadValue<Vector2>());
|
||
|
playerC.GamePlay.MoveFrontFoot.canceled += ctx => horse.SetInputFrontVector(Vector2.zero);
|
||
|
playerC.GamePlay.MoveBackFoot.canceled += ctx => horse.SetInputBackVector(Vector2.zero);
|
||
|
|
||
|
playerC.GamePlay.Enable();
|
||
|
}
|
||
|
|
||
|
}
|