Unity-3d Day03
生活随笔
收集整理的這篇文章主要介紹了
Unity-3d Day03
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
尼瑪今天研究一天腳本啊??? 這個坑啊
好多東西要記而且搞不太清楚哪能改哪是固定的??
多用用應該會好很多吧
這個是函數在腳本里的執行順序
using UnityEngine; using System.Collections;public class HelloScript : MonoBehaviour {//初始化寫在awake或startprivate GameObject gameobj;private GameObject[] gameob;void Awake(){Debug.Log("Hello!~");print("awake");}void OnEnable(){print("onEnable");}// Use this for initializationvoid Start(){print("start1");//active = false; //攝像機不啟動//gameobj = GameObject.Find("Cube");gameob = GameObject.FindGameObjectsWithTag("Player");}//一般寫一些力啊 什么的 物理方面的void FixedUpdate(){print("fixedpudate");}// Update is called once per frame//實時刷新的寫在updatevoid Update(){print("update");//gameobj.transform.Rotate(0f, 1f, 2f);foreach (GameObject item in gameob){item.transform.Rotate(0f, 1f, 2f);}}void LateUpdate(){print("lateupdate");}void OnGUI(){print("onGUI");}void OnDisable(){print("onDisable");}void OnDestroy(){print("ondestroy");}}?
MonoBehavior類:
MonoBehaviour 表示一個單一的行為。Unity中用戶對游戲對象的操作被分割成若干個
單一行為,每個單一行為都作為一MonoBehaviour類來封裝。繼承自MonoBehaviour的類,不需要自己創建它
的實例,也不能自己創建(如 new 類名)。因為所有從MonoBehaviour繼承過來的類,unity都會自動創建實例,并且調用被重載的方
法,如我們經常用到的Awake,Start, Update等。而普通類,可以用new來創建實例了。
Gameobject類:常用方法:
SetActive( bool value)
Find( String name)
FindWithTag( string tag)
FindGameObjectsWithTag( string tag)
Input類:常用的? 有鍵盤輸入和鼠標輸入
void Update () {//鼠標輸入if (Input.GetMouseButtonDown(0)){print("左鍵");}if (Input.GetMouseButton(1)){print("右鍵");}if (Input.GetMouseButton(2)){print("中鍵");}} void Update () {//鍵盤輸入if (Input.GetKey(KeyCode.W)){transform.Translate(0f, 0f, -1f);}if (Input.GetKey(KeyCode.A)){transform.Translate(-1f, 0f, 0f);}if (Input.GetKey(KeyCode.S)){transform.Translate(0f, 0f, 1f);}if (Input.GetKey(KeyCode.D)){transform.Translate(1f, 0f, 0f);}}緩慢走的方法:
Vector3 source = sphere.transform.position;Vector3 target = transform.position;Vector3 position = Vector3.Lerp(source, target, Time.deltaTime);sphere.transform.position = position;?
鍵盤輸入控制角色的另一種方式,是不是有點屌
void Update () {float horizontal = Input.GetAxis("Horizontal");float vertical = Input.GetAxis("Vertical");transform.position += Vector3.forward * vertical;transform.position += Vector3.right * horizontal;}
今天呢還研究了一下簡單的跟隨? 類似游戲里的寵物的行為
?
?
轉載于:https://www.cnblogs.com/little-sun/p/4367279.html
總結
以上是生活随笔為你收集整理的Unity-3d Day03的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: javascript之值传递与引用传递
- 下一篇: Monkey与MonkeyRunner之