日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Input类,Vector3实例

發布時間:2025/3/19 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Input类,Vector3实例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這篇文章主要是記錄聽網課的一些記錄,不一定是完全的Input的有關的,希望能給大家有幫助。

(1)

using System.Collections; using System.Collections.Generic; using UnityEngine;public class InputOne : MonoBehaviour {float xSpeed = 2.0f;float ySpeed = 2.0f;GameObject cube;// Start is called before the first frame updatevoid Start(){cube = GameObject.Find("Cube");}// Update is called once per framevoid Update(){if (Input.GetMouseButtonDown(0)){Debug.Log("左鼠標被按下");}if(Input.GetMouseButtonDown(1)){Debug.Log("右鼠標被按下");}// Debug.Log(Input.mousePosition);float v = xSpeed * Input.GetAxis("Mouse X");// Input.GetAxis("Mouse X")這個是鼠標這一幀與上一幀在X方向的偏移量float h = ySpeed * Input.GetAxis("Mouse Y");// Input.GetAxis("Mouse Y")這個是鼠標這一幀與上一幀在Y方向的偏移量cube.transform.Rotate(v, h, 0.0f);//這里關于Speed我的理解是這樣的:不要理解為速度,看成某一個固定的值就好,這樣可能會理解的更好。} }//Touch類的補充 //touchCount表示觸碰的次數。 //touches返回所有的觸碰信息。 //GetTouch(int index)里面的元素是觸碰的順序。 /*Touch對象的生命周期的結束并不是手指離開屏幕后立刻銷毀 如果一根手指在同一位置快速點擊,則視作同一Touch對象 tapCount為Touch對象所對應的手指點擊屏幕的次數 myTouch.tapCount*/

(2)

using System.Collections; using System.Collections.Generic; using UnityEngine;public class Vector: MonoBehaviour {private Vector3 a;private Vector3 b;// Start is called before the first frame updatevoid Start(){a = new Vector3(3, 2, 1);b = new Vector3(1.5f, 1.0f, 0.5f);}// Update is called once per framevoid Update(){}//向量之間的點乘與叉乘。private void OnGUI(){float c = Vector3.Dot(a, b);//c為a,b的點乘;//求角度,Acos為cos的反函數。float angle = Mathf.Acos(Vector3.Dot(a.normalized, b.normalized)) * Mathf.Rad2Deg;//標簽,GUI控件GUILayout.Label("兩者的點乘為:" + c);GUILayout.Label("兩者的角度為:" + angle);//用兩個向量的叉乘來求角度,所謂叉乘就是a的模乘以b的模乘上兩者角度的sin值。float cc = Mathf.Asin(Vector3.Distance(a.normalized, b.normalized)) * Mathf.Rad2Deg;GUILayout.Label("兩者的角度為:" + cc);} }

上面這段代碼主要是介紹向量之間的點乘和叉乘。

(3)

using System.Collections; using System.Collections.Generic; using UnityEngine;public class Vector22 : MonoBehaviour {// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){}private void OnGUI(){if (GUILayout.Button("creatCube")){//創建一個實例的cube,并且賦予其材質為紅色,最后加了一個剛體組件,有了這個組件的話物體就會受重力GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube);obj.GetComponent<Renderer>().material.color = Color.red;obj.transform.position = new Vector3(0.0f, 10.0f, 0.0f);obj.AddComponent<Rigidbody>();}if(GUILayout .Button("creatshpere")){GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);sphere.AddComponent<Rigidbody>();sphere.GetComponent<Renderer>().material.color = Color.blue;}}}

這段代碼的話就是通過代碼來創建物體,然后給物體加想要的組件,實現顏色的變化。

希望能夠對大家有幫助!

總結

以上是生活随笔為你收集整理的Input类,Vector3实例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。