Search Unity

Show a text damage after the monster is hit

Discussion in 'Immediate Mode GUI (IMGUI)' started by digO, Nov 22, 2014.

  1. digO

    digO

    Joined:
    Mar 20, 2014
    Posts:
    23
    Well, im trying to show a text damage when the monster is hit, using world coordinates.

    GameObject damageGameObject = (GameObject)Instantiate(damageTextPrefab);
    damageGameObject.transform.SetParent(transform.FindChild("Auxiliares"));
    damageGameObject.transform.localPosition = Vector3.zero;
    damageGameObject.transform.localRotation = Quaternion.identity;
    damageGameObject.GetComponentInChildren<Text>().text = dano.ToString();

    And its working the text is showing above the monster, but the text is showing on the contrary, like if u see a text in one mirror, i think the problem is that the text is following the monster rotation.
    U guys know any way to the text show to the camera and not follow the monster rotation?
    Thanks
     
  2. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    Could possibly just try LookAt.

    Code (csharp):
    1.  
    2. damageGameObject.transform.LookAt(Camera.main.transform);
    3.  
     
    Magiichan and digO like this.
  3. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    Also - if you're going to just reference transform a bunch of times, maybe just something like:

    Code (csharp):
    1.  
    2. Transform damageTransform = Instantiate(prefab, Vector3.zero, Quaternion.identity) as Transform;
    3. damageTransform.SetParent(transform.FindChild("Auxiliares"));
    4. damageTransform.LookAt(Camera.main.transform);
    5. damageTransform.GetComponentInChildren<Text>().text = dano.ToString();
    6.  
    (syntax may be off - untested)
     
    Magiichan and digO like this.
  4. digO

    digO

    Joined:
    Mar 20, 2014
    Posts:
    23
    thanks man