2014-11-21 71 views
1

我不明白爲什麼OnDrawGizmos()方法在Start()方法和Update()方法中都沒有被調用,但它在我運行Unity項目時執行。爲什麼我在Unity中調用我的方法時,我沒有在代碼中調用它?

using UnityEngine; 
using System.Collections; 

public class PlayerController : MonoBehaviour 
{ 
    public Transform grounder; 


    // Use this for initialization 
    void Start() { 

    } 

    // Update is called once per frame 
    void Update() { 

    } 

    void OnDrawGizmos(){ 
     Gizmos.color = Color.white; 
     Gizmos.DrawSphere (grounder.position, 1); 
    } 
} 

回答

2

因爲Unity在實現MonoBehaviour的類上調用它,所以根據documentation

+0

我明白了。感謝兄弟! – 2014-11-21 12:45:21

3

顧名思義,OnDrawGizmozs被統一引擎調用。這是一個消息函數,可以在實現MonoBehaviour的類上調用。從文檔Excert:

說明,如果你想畫,同時也是 揀選和總是畫小玩意

實現OnDrawGizmos。

http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnDrawGizmos.html

這意味着你不必自己調用該函數。

+0

我明白了。感謝兄弟! – 2014-11-21 12:44:55

相關問題