我正在编写一个脚本,当我想将它添加到 GameObject 时,我注意到启用检查消失了,并且无法将脚本拖到该组件 Event Script
的检查器中。
我尝试更改脚本的名称,但没有任何变化。
要添加的脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EventScript : MonoBehaviour
{
private GameObject obj;
public SaveObjScript saveObjScript;
public SpawnScript spawnScript;
public void InitObject(){
Debug.Log("OBJETO A ACCIONAR ES: " + saveObjScript.getObject().name);
//obj = saveObjScript.getObject();
}
public void ChangeColor(){
InitObject();
Renderer rend = obj.GetComponent<Renderer>();
rend.material.color = Random.ColorHSV();
}
public void RemoveObj(){
InitObject();
Destroy(obj);
spawnScript.mTotalObjetos --;
}
}
最佳答案
它没有复选框,因为它没有实现任何内置方法,如 Start
或 Update
或 FixedUpdate
关心是否组件已启用。
来自MonoBehaviour
documentation :
Note: There is a checkbox for disabling MonoBehaviour on the Unity Editor. It disables functions when unticked. If none of these functions are present in the script, the Editor does not display the checkbox.
关于c# - 该脚本缺少一个复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58453028/