欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Unity3D獲取當(dāng)前鍵盤按鍵及Unity3D鼠標(biāo)、鍵盤的基本操作

 更新時(shí)間:2015年11月11日 14:29:38   投稿:mrr  
這篇文章主要介紹了Unity3D獲取當(dāng)前鍵盤按鍵及Unity3D鼠標(biāo)、鍵盤的基本操作的相關(guān)資料,需要的朋友可以參考下

獲取當(dāng)前鍵盤按鍵,代碼如下:

using UnityEngine;
using System.Collections;
public class GetCurrentKey : MonoBehaviour {
 KeyCode currentKey;
 void Start ()
 {
  currentKey = KeyCode.Space;
 }
 void OnGUI()
 {
  if (Input.anyKeyDown)
  {
   Event e = Event.current;
   if (e.isKey)
   {
    currentKey = e.keyCode;
    Debug.Log("Current Key is : " + currentKey.ToString());
   }
  }
 }
}

下面給大家介紹Unity3D鼠標(biāo)、鍵盤的基本操作

鍵盤:  

GetKey             當(dāng)通過(guò)名稱指定的按鍵被用戶按住時(shí)返回true
GetKeyDown   當(dāng)用戶按下指定名稱的按鍵時(shí)的那一幀返回true。
GetKeyUp        在用戶釋放給定名字的按鍵的那一幀返回true。 
GetAxis(“Horizontal")和GetAxis(“Verical”) 用方向鍵或WASD鍵來(lái)模擬-1到1的平滑輸入   

鍵盤判斷:   

If(Input.GetKeyDown(KeyCode.A)){//KeyCode表示包含鍵盤所有鍵     
print(“按下A鍵”); }  If(Input.GetKeyUp(KeyCode.D)){//當(dāng)按D鍵松開(kāi)時(shí)    
print(“松開(kāi)D鍵”); }  If(Input.GetAxis(“Horizontal")){//當(dāng)按下水平鍵時(shí)   
print(“按下水平鍵”); }  If(Input.GetKeyUp("Verical“)){當(dāng)按下垂直鍵時(shí)    
print(“按下垂直鍵”); }  

鼠標(biāo):  

GetButton           根據(jù)按鈕名稱返回true當(dāng)對(duì)應(yīng)的虛擬按鈕被按住時(shí)。
GetButtonDown      在給定名稱的虛擬按鈕被按下的那一幀返回true。
GetButtonUp        在用戶釋放指定名稱的虛擬按鈕時(shí)返回true。  

鼠標(biāo)判斷:   

if(Input.GetButton("Fire1")){//Fire1表示按下鼠標(biāo)左鍵       
print(“按下鼠標(biāo)左鍵”); }  if (Input.GetMouseButton(0)) {//0表示鼠標(biāo)左鍵     
Debug.Log("按下鼠標(biāo)左鍵"); }   if (Input.GetMouseButton(1)) {//1表示鼠標(biāo)右鍵    
Debug.Log("按下鼠標(biāo)右鍵");  }  if (Input.GetMouseButton(2)) {//2表示鼠標(biāo)中鍵    
Debug.Log("按下鼠標(biāo)中鍵"); } 

給物體施加普通力:   

1、先給物體添加剛體 
2、transform.rigidbody.AddForce(0,0,1000);  一個(gè)簡(jiǎn)單例子讓小球撞破墻: 

代碼如下: 

using UnityEngine; 
using System.Collections; 
public class Cube : MonoBehaviour { // Use this for initialization 
void Start () { }  // Update is called once per frame void Update () { 
if(Input.GetKey(KeyCode.W)){//當(dāng)鼠標(biāo)按下W鍵時(shí),小球向前移動(dòng) 
transform.Translate(Vector3.forward); 
} 
if(Input.GetKey(KeyCode.S)){當(dāng)鼠標(biāo)按下S鍵時(shí),小球向后移動(dòng)  
transform.Translate(Vector3.back); 
天貓雙十一活動(dòng)
 } if(Input.GetKey(KeyCode.A)){當(dāng)鼠標(biāo)按下A鍵時(shí),小球向左移動(dòng) 
 transform.Translate(Vector3.left); 
 } 
 if(Input.GetKey(KeyCode.D)){當(dāng)鼠標(biāo)按下D鍵時(shí),小球向右移動(dòng) 
 transform.Translate(Vector3.right); 
 } if(Input.GetButton("Fire1")){//當(dāng)點(diǎn)擊鼠標(biāo)左鍵時(shí),小球撞塌墻 
 transform.rigidbody.AddForce(0,0,200);//物體向前移動(dòng)的力為200 
 } 
 } 
 } 

相關(guān)文章

最新評(píng)論