鼠标获取
using UnityEngine;
using System.Collections;public class Input_Mouse : MonoBehaviour {void Update()
{
//if (Input.GetMouseButtonDown (0)) {
//Debug.Log ("按下了鼠标左键");
//}
//
//if (Input.GetMouseButtonUp (0)) {
//Debug.Log ("抬起了鼠标左键");
//}
//
//if (Input.GetMouseButton (0)) {
//Debug.Log ("按住了鼠标左键");
//}Debug.Log (Input.mousePosition);
}
}
按键获取
using UnityEngine;
using System.Collections;public class Input_Key : MonoBehaviour {void Update()
{
//当用户按下了空格键盘,if成立(为真)
if (Input.GetKeyDown (KeyCode.Space)) {
Debug.Log ("按下了空格!!!");
}if (Input.GetKey (KeyCode.Space)) {
Debug.Log ("按住了空格!!!");
}if (Input.GetKeyUp (KeyCode.Space)) {
Debug.Log ("抬起了空格!!!");
}
}
}
WASD获取
using UnityEngine; using System.Collections; public class Virtual : MonoBehaviour { void Update() { float h = Input.GetAxis ("Horizontal"); float v = Input.GetAxis ("Vertical"); Debug.Log (v); } }