set SmoothFollow target at runtime via static var


I have a textfield in my GUI where i enter a custom name. When I instantiate my player object i change it's name to that custom name using a static var. When I debug I see it's changed, so my static var works. When i try to use that same static in my SmoothFollow script, I get this error : Assets/Standard Assets/Camera Scripts/SmoothFollow.js(9,11): BCE0005: Unknown identifier: 'ConnectionGUI'.

Anyone got an idea ? Thanks.


If I understand you correctly you're going about it the wrong way. You need to find the game object with GameObject.Find or better, GameObject.FindWithTag to get the instance of the object and then you can reference it's transform for the smooth follow script.

link textsmooth follow requires a transform to follow but name of an object is a string. the value of a text field is a string so you can asign it to a string but not to a transform. to find a gameObject with that name you should use GameObject.Find

Thanks everyone. I got it to work. I'm able to assign my prefab at runtime like this :

prefab = Instantiate(Resources.LoadAssetAtPath("Assets/playerPrefab.prefab", GameObject));

and attached the SmoothFollow by finding the gameobject and use it's transform. The transform is what got me confused but all sorted now.