在我的层次结构中,这是我的arrangement of gameobjects。
这是我获取MediaPlayer gameObject的代码。
[SerializeField]
GameObject ump; // lets access the ump gameobject
void Update()
{
if (tzPlayInfo.Instance.MAKING_GAME_OBJECT == false)
{
//find the gameobject through getting the child of every component/gameobject
ump = this.gameObject.transform.GetChild(0).GetChild(1).GetChild(1).GetChild(1).GetChild(0).GetChild(1).gameObject;
if (ump != null) {
//Uses an If directives for the platform dependencies
#if UNITY_ANDROID
ump.GetComponent<UniversalMediaPlayer>()._chosenPlatform = 2;
if (ump.GetComponent<UniversalMediaPlayer>()._chosenPlatform == 2)
{
Debug.Log("UMP property is set to Android");
this.enabled = false;
} else
{
Debug.Log("Couldn't set the property to Android");
}
#elif UNITY_STANDALONE
ump.GetComponent<UniversalMediaPlayer>()._chosenPlatform = 0;
if(ump.GetComponent<UniversalMediaPlayer>()._chosenPlatform == 0){
Debug.Log("UMP property is set to StandAlone/Windows");
this.enabled = false;
} else {
Debug.Log("Couldn't set the property to StandAlone/Windows");
}
#else
#endif
} else
{
Debug.Log("Could not get the gameobject UMP");
}
现在它总是给我一个错误,虽然我得到了我想要的东西。