在uinty中获取子对象的float变量

时间:2016-03-01 17:43:04

标签: unity3d gameobject

我有Unit gameObject,其中包含2个子项目:Monster和HealthBar。 现在Health有float - max_Health,我想使用onTriggerEnter访问它。

print(co.transform.GetChild(1)); 

给我" HealthBar"这意味着我得到了正确的子对象,但现在我怎么能得到它的浮点变量的含义" max_Health" ?

我试过这个:

print(co.transform.GetChild(1).transform.Find("max_Health"));

但是得到了Null。那是错的。我怎么能得到它?

print(co.transform.GetChild(1).Find("max_Health")); 无法正常工作

print(co.transform.GetChild(1).Find("float max_Health")); 无效。

还有什么可以做???????

更新

GameObject GG = GameObject.Find("GameObject co.transform.GetChild(1)");
Health bScript = GG.GetComponent<Health>();
print(bScript.max_Health);

给我错误

NullReferenceException: Object reference not set to an instance of an object
Tower.OnTriggerEnter (UnityEngine.Collider co) (at Assets/Scripts/Tower.cs:23)

0 个答案:

没有答案