- Home /
GameObject.Find not orking
var playerSpawn : Transform; var player : Transform;
var golemSpawn : Transform; var golem : Transform;
function Awake () { playerSpawn = GameObject.Find("StartUp"); golemSpawn = GameObject.Find("StartUp"); }
Just a quick snippet from a script I'm trying to get working, but it keeps saying "Cannot convert 'UnityEngine.GameObject' to 'UnityEngine.Transform'.
... which means I can't use this script to find an object to assign as a Transform, which is bull honkey, because I know it can be done. So how do I go by doing this, since this is obviously wrong
Answer by Eric5h5 · May 11, 2013 at 05:25 PM
GameObject.Find returns GameObject, and your variables are of type Transform. Either make your variables GameObject (is there any reason you're using Transform?) or use GameObject.Find().transform.
Originally before I tried using this script, I just dragged and dropped them in. But when I instantiate a prefab with this script in, the transforms were empty, so I realized I would need to change it up. How would I change the variables from transform to GameObject?
Okay, new issue came up after I switched it out. Rest of the script uses things like playerSpawn.position, playerSpawn.rotation... Is there a page or link I could get that would show me the counter parts to this? Because those are transforms, not GameObject references