In my 3d game, i would like to display a text 'near' the impact point of a bullet. I think i'm having problems setting properly text position. This is my code. The script is attached to an object Canvas. position is the Vector3 impact position.

GameObject obj = new GameObject ();
Text _text = obj.AddComponent<Text> ();

_text.transform.position = position;
_text.text = message;
_text.fontSize = startSize;
_text.color = color;

I'm pretty sure i've to convert from a world space to a 'user interface' space. Thanks


Try this:

_text.transform.position = camera.WorldToScreenPoint(position);

You'd need to get a reference to the camera first. See an example from the docs

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.