49
社区成员
发帖
与我相关
我的任务
分享
本教程演示如何在 Unity 项目中获取用于输入的按钮或键,以及这些轴的行为或如何通过 Unity Input Manager 进行修改。
KeyInput
using UnityEngine;
using System.Collections;
public class KeyInput : MonoBehaviour
{
public GUITexture graphic;
public Texture2D standard;
public Texture2D downgfx;
public Texture2D upgfx;
public Texture2D heldgfx;
void Start()
{
graphic.texture = standard;
}
void Update ()
{
bool down = Input.GetKeyDown(KeyCode.Space);
bool held = Input.GetKey(KeyCode.Space);
bool up = Input.GetKeyUp(KeyCode.Space);
if(down)
{
graphic.texture = downgfx;
}
else if(held)
{
graphic.texture = heldgfx;
}
else if(up)
{
graphic.texture = upgfx;
}
else
{
graphic.texture = standard;
}
guiText.text = " " + down + "\n " + held + "\n " + up;
}
}