无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

unity3d VR游戲控制基本腳本。

2021-05-30 10:38 作者:擁抱大自然  | 我要投稿

手機(jī)連接藍(lán)牙手柄或者鍵盤。

上下左右鍵控制前后左右移動(dòng)。

雙擊左或者右,視角轉(zhuǎn)動(dòng)45°。

(即便你沒有陀螺儀的手機(jī)一樣可以用。)

手機(jī)左右傾斜30度,視角左右移動(dòng)。

手機(jī)向前傾45度,人物向前走。

(你手機(jī)有陀螺儀,但沒有連接控制手柄或者鍵盤,一樣可以用)


=======


using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class playerControl : MonoBehaviour

{

? ? public int playerSpeed = 1;

? ? public int rSpeed = 50;

? ? public int headLeanAngle=45;

? ? public int headTilt=30;? ??


? ? public float DOUBLE_CLICK_TIME = 0.2f;

? ? private float lastClickTime;??

? ?

? ? void Update()

? ? {? ? ? ?

? ? ? ? //KeyBoard Input:=============================

? ? ? ? if (Input.GetKey("up"))

? ? ? ? {

? ? ? ? ? ? ?transform.position = transform.position + Camera.main.transform.forward * playerSpeed * Time.deltaTime;

? ? ? ? }


? ? ? ? if (Input.GetKey("down"))

? ? ? ? {

? ? ? ? ? ? ?transform.position = transform.position - Camera.main.transform.forward * playerSpeed * Time.deltaTime;

? ? ? ? }


? ? ? ? if (Input.GetKey("left"))

? ? ? ? {

? ? ? ? ? ? //transform.Rotate(new Vector3(0, -1, 0) * Time.deltaTime * playerSpeed*rSpeed, Space.World);

? ? ? ? ? ? ?transform.position = transform.position - Camera.main.transform.right * playerSpeed * Time.deltaTime;

? ? ? ? }


? ? ? ? if (Input.GetKey("right"))

? ? ? ? {

? ? ? ? ? ? //transform.Rotate(new Vector3(0, 1, 0) * Time.deltaTime * playerSpeed*rSpeed, Space.World);

? ? ? ? ? ? ?transform.position = transform.position + Camera.main.transform.right * playerSpeed * Time.deltaTime;

? ? ? ? }


? ? ? ? //keyboard double click:

? ? ? ? if (Input.GetKeyUp("right"))

? ? ? ? {

? ? ? ? ? ? float timeSinceLastClick = Time.time - lastClickTime;

? ? ? ? ? ? Debug.Log(lastClickTime +"? ?"+ Time.time +"? ?"+ timeSinceLastClick );

? ? ? ? ? ? if(timeSinceLastClick<=DOUBLE_CLICK_TIME)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? transform.Rotate(new Vector3(0, 1, 0) * 30, Space.World);

? ? ? ? ? ? }

? ? ? ? ? ? lastClickTime = Time.time;

? ? ? ? }


? ? ? ? if (Input.GetKeyUp("left"))

? ? ? ? {

? ? ? ? ? ? float timeSinceLastClick = Time.time - lastClickTime;

? ? ? ? ? ? Debug.Log(lastClickTime +"? ?"+ Time.time +"? ?"+ timeSinceLastClick );

? ? ? ? ? ? if(timeSinceLastClick<=DOUBLE_CLICK_TIME)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? transform.Rotate(new Vector3(0, -1, 0) * 30, Space.World);

? ? ? ? ? ? }

? ? ? ? ? ? lastClickTime = Time.time;

? ? ? ? }


? ? ? ? //Head Gesture input:================================


? ? ? ? Debug.Log(Camera.main.transform.eulerAngles);



? ? ? ? if (Camera.main.transform.eulerAngles.z>headTilt && Camera.main.transform.eulerAngles.z<90)

? ? ? ? {

? ? ? ? ? ? ? transform.Rotate(new Vector3(0, -1, 0) * Time.deltaTime * playerSpeed*rSpeed, Space.World);

? ? ? ? }


? ? ? ? if (Camera.main.transform.eulerAngles.z>270 && Camera.main.transform.eulerAngles.z<360-headTilt)

? ? ? ? {

? ? ? ? ? ? ? transform.Rotate(new Vector3(0, 1, 0) * Time.deltaTime * playerSpeed*rSpeed, Space.World);

? ? ? ? }


? ? ? ? if (Camera.main.transform.eulerAngles.x>headLeanAngle && Camera.main.transform.eulerAngles.x<90)

? ? ? ? {

? ? ? ? ? ? ?transform.position = transform.position + Camera.main.transform.forward * playerSpeed * Time.deltaTime;

? ? ? ? }

? ? }

}


unity3d VR游戲控制基本腳本。的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
孝感市| 英德市| 澄江县| 揭西县| 通化县| 兴化市| 苏州市| 黎川县| 苏尼特左旗| 英吉沙县| 海晏县| 阆中市| 炎陵县| 抚远县| 新晃| 兰考县| 克什克腾旗| 时尚| 额济纳旗| 马关县| 苍山县| 高邑县| 宣汉县| 太仓市| 罗源县| 玉门市| 闵行区| 惠水县| 克东县| 仲巴县| 武川县| 林州市| 长武县| 保德县| 河南省| 梁河县| 沧州市| 山东省| 上思县| 尼玛县| 西乌|