描述

重置为默认值。

当用户点击 Inspector 上下文菜单中的“Reset”按钮或第一次添加组件时,将调用 Reset。 该函数只能在 Editor 模式下调用。Reset 最常用于在 Inspector 中提供良好的默认值。

// Sets target to a default value.
// This could be used in a follow camera.

using UnityEngine;

public class Example : MonoBehaviour { public GameObject target;

void Reset() { //Output the message to the Console Debug.Log("Reset"); if (!target) target = GameObject.FindWithTag("Player"); } }