如题,Event.current获取出来为NULL,然而获取当前输入的keyCode我需要获取到Evert.current。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private Animator animator;//玩家的动画
// Start is called before the first frame update
void Start()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
Move();
}
void Move()
{
if (!animator.GetBool("OnMoving") && Input.anyKey)
{
Debug.Log(Event.current);
if (Input.anyKeyDown)
{
Event e = Event.current;
if (e.isKey)
{
Debug.Log("Current Key is : " + Event.current.keyCode.ToString());
}
}
}
}
}
https://tieba.baidu.com/p/6840492604
这个Event.Current事件是给编辑器用的,不是给运行时.
而且这个AnyKey的触发条件可能是鼠标,不一定是键盘按键.
最近我也遇到了这个问题,后来我发现测试这段代码时,我还没有在场景中添加EventSystem,添加后就正常了.你可以检查一下场景中是否添加EventSystem