【发布时间】:2016-03-27 20:17:41
【问题描述】:
我有一个类,我想创建serializable(在检查器中查看一些公共变量),但我还需要在该类中使用Coroutines。要在我的班级中使用Coroutines,我必须从 MonoBehaviour 继承它。但是我不能使用serializable 类的功能。
public class Act1HomeAwake : MonoBehaviour
{
public Act1_1HomeAwake act1_1HomeAwake;
public void StartAct1(int subActNumber)
{
switch(subActNumber)
{
case 1: act1_1HomeAwake.StartSubAct1_1(); break;
}
}
}
[System.Serializable]
public class Act1_1HomeAwake // : MonoBehaviour
{
// don't see this 2 variables in the inspector WITH inheriting from MonoBehaviour
public OpenCloseAnimation openCloseEyesScript;
public Text textTipsTasksComponent;
// WITHOUT inheriting from MonoBehaviour compiler don't understand this construction
StartCoroutine("OpenCloseEyesAnimation");
}
【问题讨论】:
-
您的代码不是有效的 C#?您正在尝试从任何类成员之外调用方法。
标签: c# serialization unity3d