unity 人機交互

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

public class intput : MonoBehaviour {

//float b = 0, c = 100, f = 0.2f;

//public Transform ball;

void Start () {

}

 

 

void Update() {

//if (Input.GetKey(KeyCode.W))

//{

// Debug.Log("是否輸入W");

// transform.position += Vector3.forward * Time.deltaTime;

//}

//if (Input.GetKey(KeyCode.S))

//{

// Debug.Log("是否輸入s");

// transform.position += Vector3.back * Time.deltaTime;

//}

////if (Input.GetKey (KeyCode.A))

//{

// Debug.Log("是否輸入a");

// transform.position += Vector3.left * Time.deltaTime;

//}

//if (Input.GetKey (KeyCode.D))

//{

// Debug.Log("是否輸入d");

// transform.position += Vector3.right * Time.deltaTime;

//}

// transform.Translate(Vector3.forward*Time.deltaTime);

//if (Input.GetKeyUp(KeyCode.O))

//{

// Debug.Log("Input.GetKeyUp(KeyCode.O)");

//}

//Input.GetKeyDown:按下某個按鍵第一幀時返回ture

//Input.GetKey:鬆開時按鍵期間返回ture

//Input.GetKeyup:鬆開某個按鍵第一幀返回ture

//if (Input.GetMouseButtonDown(0))

//{

// Debug.Log("按下鼠標左鍵");

//}

//if (Input.GetMouseButtonDown(1))

//{

// Debug.Log("按下鼠標左右鍵");

//}

//if (Input.GetMouseButtonDown(2))

//{

// Debug.Log("按下鼠標滑輪");

//}

//if (Input.GetMouseButton(0))

//{

// Debug.Log("長按鼠標左鍵");

 

//}

//if (Input.GetMouseButton(1))

//{

// Debug.Log("長按鼠標右鍵");

 

//}

//if (Input.GetMouseButton(2))

//{

// Debug.Log("長按下鼠標滑輪");

//}

////Input.GetAxis獲取虛擬軸

////horizontal;獲取水平方向

////vertical獲取垂直方向

//float hor = Input.GetAxis("Horizontal");

//float ver = Input.GetAxis("Vertical");

 

//transform.Translate(0,0,ver*Time.deltaTime);//前進後退

//transform.Rotate(0,hor,0);//旋轉

 

//Debug.Log("hor:"+hor);

//Debug.Log("ver:"+ver);

//獲取鼠標光標一幀內屏幕上的移動距離

//Debug.Log("x="+Input.GetAxis("Mouse X"));//水平方向

//Debug.Log("y="+Input.GetAxis("Mouse Y"));//垂直方向

 

 

//float a = Mathf.Tan(90);

// Debug.Log(a);

// int age = 200;

//age= Mathf.Clamp(age,18,19);/*限制一個值在某個範圍

// 小於最小值則返回最小值

// 大於最大值則返回最大值*/

// Debug.Log("age:"+age);

// Mathf.Clamp01();//限制值在0與1之間

//差值(插值)通過差值係數f 來返回b和c差值的比例

 

//float g = Mathf.Lerp(b,c,f);

//Debug.Log(g);

// : 物體移動用Vector3.Lerp

//transform.position= Vector3.Lerp(

// transform.position,ball.position,0.5f);

 

//得到fieldofview

//鼠標控制攝像頭遠近

float field = Camera.main.fieldOfView;

field += Input.GetAxis("Mouse ScrollWheel")*20f;

 

Camera.main.fieldOfView =

Mathf.Clamp(field,30,100);//限制在30到100;

//鼠標控制攝像頭的視角

 

float h = Input.GetAxis("Mouse X");

float v = Input.GetAxis("Mouse Y");

if (h!=0)

{

Camera.main.transform.Rotate(Vector3.up*Time.deltaTime*h*90f,Space.World);

}

if (v!=0)

{

Camera.main.transform.Rotate(Vector3.left * Time.deltaTime * v * 90f, Space.World);

}

}

}

 

 

 

public class Colliderscript : MonoBehaviour {

private void OnMouseDown() {

Debug.Log(" 按下鼠標");

}

private void OnMouseEnter() {

Debug.Log("進入 ");

}

private void OnMouseDrag() {

Debug.Log("拖拽"); }

private void OnMouseOver() {

Debug.Log("懸停");

}

private void OnMouseUp() {

Debug.Log("鼠標擡起時");

}

private void OnMouseUpAsButton() {

Debug.Log("鼠標在 物體上按下擡起時一個完整過程");

}

private void OnMouseExit() {

Debug.Log("鼠標從物體身上離開");

}

 

}

 

 

//Debug.Log("鼠標拖拽");

//Vector3 Mpousepos = Input.mousePosition;

//Debug.Log("鼠標點位置"+ Input.mousePosition);

//Vector3 mouseworldpos=

//Camera.main.ViewportToWorldPoint(

// new Vector3(Mpousepos.x / Screen.width,

// Mpousepos.y / Screen.height, 10));

//屏幕座標點改成世界座標點;

//將視口座標系轉變成世界座標系,game的左下角(0,0),右上角是(1,1)

//屏幕座標系game的左下角(0,0):右上角是(screen。width,scree。height)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章