using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//这里的特性也可以使用ProjectSettings中Script Execution Order 进行调节和替代
[DefaultExecutionOrder(-200)]
public class InputManager : MonoBehaviour
{
public float Horizontal { get; private set; }
public bool JumpPressed { get; private set; }
public bool JumpHold { get; private set; }
public bool CrouchPressed { get; private set; }
public bool CrouchHold { get; private set; }
private bool isReadyClearUp;
void Start()
{
}
void Update()
{
//如果游戏结束
//清除输入
ClearInput();
//电脑输入
ProcessInputs();
//移动端输入
Horizontal = Mathf.Clamp(Horizontal, -1f, 1f);
}
private void FixedUpdate()
{
//每0.02s清除一次
isReadyClearUp = true;
}
void ClearInput()
{
if (!isReadyClearUp)
{
return;
}
Horizontal = 0f;
JumpHold = false;
unity中进行输入的模板代码
最新推荐文章于 2023-12-02 23:50:31 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)