Text follow object in unity 5

As an image could obviously make an image within a canvas move with an object, so that the image or text follow the object on top of the object

Not entirely sure what you’re asking, but I’m assuming that you want a UI element to follow the world space of a GameObject. In that case, you’re going to need to use this code:

transform.position = Camera.main.WorldToScreenPoint(Vector3 worldLocation);

And place that into the UI GameObject, and set the Vector3 worldLocation to the transform.position of the object you want it to follow.

Or just make the world space canvas a child of the thing it should follow…

error CS1525: Unexpected symbol `worldLocation’

what is the problem ?¿

I’ve tried to do it but it does not work, could you help me?

is never sufficient information when it comes to explaining a problem :slight_smile:

// in the inspector, drag the object you want to follow into this slot.
[SerializedField] Transform FollowedObj;

// in update or some timed routine..
transform.position = Camera.main.WorldToScreenPoint(FollowedObj.position);

This is essentially what the responder meant. You copied it in without thinking it over much, I think…

thanks so much but can you explained why is “SerializedField”?¿

error CS0246: The type or namespace name `SerializedField’ could not be found. Are you missing an assembly reference?

what is this error ?

edit: Okay i fix the error delete the SerializedField and run the game. Thanks for help me and make this working

No problem. SerializedField (maybe I mispelled it or you’re not using C# and it doesn’t work in unityscript : one of those 2 things) just means that you can interact with the variable in the inspector, but it’s still private (to the class). Normally, only public fields can be seen in the inspector.
You could change it to public :slight_smile: That was so you can drag the object you want to follow to the script.
I’m glad it’s working , either way.

Unity has a great documentation. Google-ing SerializeField (without d) brought up this:

I did sell it wrong. Thanks :slight_smile: Too used to typing “[SF” in the IDE :wink: