Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to make a TextMesh appear when ever an enemy prefab is hit.

I currently have this functionality working. However, the text doesn't face the direction the players camera is looking.

At the moment my OnCollisionEnter method contains the following line of code:

GameObject _go = (GameObject)Instantiate(_hitPrefab, collision.gameObject.transform.position, Camera.mainCamera.transform.rotation);

This line happily creates my TextMesh whenever my enemy is hit. I know my issue has something to do with my rotation quaterion, but I have no idea what pass in so it faces my camera. As you can see, I tried setting it Quaterion.Idenitiy thinking it'll show the same way as the enemy it's associated to, but that doesn't work either.

Each time the textmesh appears, its back to front for the player and at a slight angle.

Could someone please help me in getting it so the score always faces the players camera no matter what way he is facing?

share|improve this question
up vote 3 down vote accepted

You are simply copying the main camera's rotation in your code snippet, try this method:

GameObject _go = (GameObject)Instantiate(_hitPrefab, 
        collision.gameObject.transform.position, Quaternion.identity);

You should also have a look into Quaternion.LookRotation.


This is a very useful community script for camera facing, the results may be slightly better:

share|improve this answer
Thank you. Knew it was something silly i wasn't doing. – N0xus Mar 14 '13 at 11:29
No problem, I've edited the answer with a link to a very useful script, it may give you slightly better results if you want the TextMesh to be "flat on" facing the camera. – Caius Eugene Mar 14 '13 at 11:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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