Unity 프로젝트를 만들고 있는데 다른 활성 스크립트의 일부 UI 텍스트를 편집해야합니다 (활성 장면에 연결되지 않음). 내가 무엇다른 장면에서 활성 장면의 GameObject를 편집하는 방법은 무엇입니까?
는
Scene scene = SceneManager.GetActiveScene();
Debug.Log (scene.name);
if (scene.name == "RangeView")
{
List<GameObject> activeObjects = new List<GameObject>();
scene.GetRootGameObjects(activeObjects);
for (int i = 0; i < activeObjects.Count; ++i)
{
GameObject gameObject = activeObjects[ i ];
if (gameObject.name == "Clubdigit") {
gameObject.GetComponent<Text>().text = 10.ToString();
}
else if (gameObject.name == "Balldigit") {
gameObject.GetComponent<Text>().text = 10.ToString();
} else if (gameObject.name == "Distancedigit") {
gameObject.GetComponent<Text>().text = 10.ToString();
} else if (gameObject.name == "Ballspeeddigit") {
gameObject.GetComponent<Text>().text = 10.ToString();
} else if (gameObject.name == "Distancedigit2") {
gameObject.GetComponent<Text>().text = 10.ToString();
} else if (gameObject.name == "Backspindigit") {
gameObject.GetComponent<Text>().text = 10.ToString();
} else if (gameObject.name == "Sidespindigit") {
gameObject.GetComponent<Text>().text = 10.ToString();
}else if (gameObject.name == "Launchangleindigit") {
gameObject.GetComponent<Text>().text = 10.ToString();
}
}
}
업데이트는 현장에 반영되지 않습니다이다. 활성 장면으로 어떻게 업데이트합니까?
나는 꽤 당신을 따르고 있지 않습니다 ... 스크립트가 실행되고 있지 않으면 아무 일도 일어나지 않을 것입니다. 어떤 목적으로 이것을하고 있는지 설명해 주시겠습니까? 또한 코드의 가독성을 높이는 리팩토링을 할 것입니다. – Maakep
감사합니다. 나는 그 길을 발견했다. 게임 개체의 하위를 검색해야합니다. – batuman