Posts

Showing posts from July, 2021

Unity 鍵盤偵測時機(對新手很重要,建議看)

Unity 鍵盤偵測時機(對新手很重要,建議看) [description] 哥最近遇到很令人匪夷所思的問題,但我目前解決了。花了我幾天幾次的思考終於意外解決了。 我要提醒大家這個微小細節,微小到你不容易察覺有此概念。 我的問題是,當我剛開始執行時鍵盤按鈕是有作用的,但當我選擇看Console的輸出訊息我按鍵盤時沒任何作用。當我又選擇Project模式時他又有作用。 所以我合理推測,鍵盤偵測 只有在Project模式下會有作用 , 在Console模式下沒作用 。 我們下次見,掰掰。

Awake() v.s. Start() v.s. Update() v.s. FixedUpdate() v.s. LateUpdate()

Image
Awake() v.s. Start() v.s. Update() v.s. FixedUpdate()  Update() , FixedUpdate() , LateUpdate() 為不斷執行的函數 Awake(),Start()為一次執行的函數 細節稍後做解釋: 流程: 大致如下 Awake()->Start()->FixedUpdate() Awake()->Start()->Update()->LateUpdate() 函數介紹: 我只說正常情況下,所謂的正常情況是沒有執行續中斷或例外被拋出或該物件被設定為enable或disable等造成程式碼無法以正常程序執行。 程式語言C/C++/C#管理程式中函數呼叫的方式很深,用到堆疊概念,若不懂得可以去google一下或修C++之類的課程,我稍微講解一下。若沒興趣可以跳過,直接往下看。 程式語言C/C++/C#管理函數呼叫的方式 (programmingconception.blogspot.com) 執行續概念很深,用到CPU的底層知識,若不懂得可以去google一下或修作業系統之類的課程,我稍微講解一下。若沒興趣可以跳過,直接往下看。 Thread(執行續) (programmingconception.blogspot.com) Awake(): void Awake(){//一次性程式碼} 當該腳本(Script)被執行時,Awake()會先被呼叫 Start(): void Start(){//一次性程式碼} 當該腳本(Script)被執行時,Awake()會先被呼叫,再呼叫Start() Update(): void Update(){//無限執行程式碼} 當該腳本(Script)被執行時,Start()被呼叫後,Update()會被呼叫,當執行完LateUpate()函數後過一禎(per frame),Update()又會被呼叫 FixedUpdate(): void FixedUpdate(){//無限執行程式碼} 當該腳本(Script)被執行時,Start()執行完,每過timeStep秒FixedUpdate()會被呼叫一次 LateUpdate(): void LateUpdate(){//無限執行程式碼} 當該腳本(Script)被執行時,Up...

實用的呼叫函式-Invoke() vs InvokeRepeating()

實用的呼叫函式-Invoke() vs InvokeRepeating() Unity: Version: 2020.3.12f1.590.2 Personal Revision: 2020.3/release b3b2c6512326 Built: Tue, 08 Jun 2021 08:46:44 GMT 1.Invoke: syntax: Invoke(string MethodName,float t) description: Invoke the method MethodName() after t seconds. [Note] (1)Notice that "MethodName" is considered as MethodName() in compiler. (2)Notice that because of (1), MethodName must be a string, so it must be quotated such as "MethodName". (3)Notice that because of (1), the rule of naming of MethodName is almost same as the rule of naming of  a variable in C#. i.e. it only can contain a uppercase or lowercase or _ or digits in the string method name. It can not contain a bracket or other special character. (4)Notice that if t is set to zero, the MethodName() will be called in the  beginning of then next Update() cycle. [Review] Debug.Log("a") means that a will be output in Unity Console. more details on the website: For Unity beginner with C# synta...

For Unity beginner with C# syntax - part1 - Debug.Log();

Image
 For Unity beginner with C# syntax - part1 - Debug.Log(); syntax: Debug.Log(string s); description: string s will be outputed in Unity Console. common issue: Q:Why did not see string s in Console? A: Check if the string s is outputed in Console or not. 1.Maybe you just did not select the output mode. It will be outputed but you can not see it. output mode was selected. output mode was NOT selected. but the message was outputed. If it is not outputed. 2.Check the script,  check the script is attached on the object. If the script is not attached, the script will not be executed. you can check it through Hierarchy -> object you select ->Inspector  Logic error 3.Check that the Debug.Log(s); was called. I recommend that test a script at beginning. such as  void Start() { Debug.Log("Hello Unity"); } ByeBye~~