0
\$\begingroup\$

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

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

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

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .