[英]Why is my method called by Unity when I don't call it in code?
I can not understand why the method OnDrawGizmos()
executes while it is not called in both the Start()
method and Update()
method, but it is executed when I run the Unity project. 我不明白为什么在Start()
和Update()
方法中都没有调用OnDrawGizmos()
方法时执行该方法,但是在我运行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);
}
}
As the name suggests, OnDrawGizmozs
gets called by the unity engine. 顾名思义,统一引擎调用OnDrawGizmozs
。 It's a message function that gets called on classes that implement MonoBehaviour. 这是一个消息函数,可在实现MonoBehaviour的类上调用。 Excert from the documentation: 来自文档的证明:
Description 描述
Implement OnDrawGizmos if you want to draw gizmos that are also pickable and always drawn. 如果要绘制也可拾取且始终绘制的小控件,请实现OnDrawGizmos。
http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnDrawGizmos.html http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnDrawGizmos.html
This means you don't need to call the function yourself. 这意味着您不需要自己调用该函数。
根据文档 ,因为它是由Unity在实现MonoBehaviour的类上调用的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.