#so just ```GameObject transform Find```
1 messages · Page 1 of 1 (latest)
No that would throw an error, that the class GameObject has no static member "transform". GameObject.Find() returns an instance of the GameObject class - that's where the transform member is. So
Transform myTransform = GameObject.Find("MyGO").transform;
But note this will throw a Null Reference Exception if GameObject.Find() fails to locate a GameObject of that name. It's better to try and handle that condition to avoid confusion later:
GameObject myObj = GameObject.Find("MyGo");
if (myObj == null) {
Debug.LogError("Couldn't find a GameObject named MyGo!");
return;
}
myTransform = myObj.transform;