Unity C#在检查器中使变量可编辑,并通过AddComponent在其他类中使用它

时间:2016-06-12 17:29:35

标签: c# unity3d

所以我有一个简单的问题:

public class Foo : MonoBehaviour {
    //Here is a variable that can be editable in the inspector
    public float A = 0f;
}

在检查员中,我将A设置为4.0

现在,在另一个班级:

public class Goop : MonoBehaviour {
    void start () {
        GameObject Foom = GameObject.Find("FooManager");
        Foo Foolee = Foom.AddComponent<Foom_Manage> ();

        print (Foolee.A);
    }
}

现在,它不是向控制台写入正确的数字4.0,而是将原始数字0写入控制台,我将其用作占位符。如何使用AddComponent成功地将变量A变为等于4.0

0 个答案:

没有答案
相关问题