欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當前位置:主頁 > 軟件編程 > C#教程 >

Unity3D獲取當前鍵盤按鍵及Unity3D鼠標、鍵盤的基本操作

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C#教程|點擊: 次

獲取當前鍵盤按鍵,代碼如下:

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鼠標、鍵盤的基本操作

鍵盤:  

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

鍵盤判斷:   

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

鼠標:  

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

鼠標判斷:   

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

給物體施加普通力:   

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

代碼如下: 

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)){//當鼠標按下W鍵時,小球向前移動 
transform.Translate(Vector3.forward); 
} 
if(Input.GetKey(KeyCode.S)){當鼠標按下S鍵時,小球向后移動  
transform.Translate(Vector3.back); 
天貓雙十一活動
 } if(Input.GetKey(KeyCode.A)){當鼠標按下A鍵時,小球向左移動 
 transform.Translate(Vector3.left); 
 } 
 if(Input.GetKey(KeyCode.D)){當鼠標按下D鍵時,小球向右移動 
 transform.Translate(Vector3.right); 
 } if(Input.GetButton("Fire1")){//當點擊鼠標左鍵時,小球撞塌墻 
 transform.rigidbody.AddForce(0,0,200);//物體向前移動的力為200 
 } 
 } 
 } 

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有