Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

I got my server working properly and even added jumping but how do I make UI hide when looking away?

Discussion in 'Multiplayer' started by Durins-Bane, Jan 29, 2017.

  1. Durins-Bane

    Durins-Bane

    Joined:
    Sep 21, 2012
    Posts:
    175
    Here is what I have so far!


    How do I make the HealthBars hide when the camera is facing away?
    Can you see in the video how they are floating all over the place looking horrible?
     
  2. Durins-Bane

    Durins-Bane

    Joined:
    Sep 21, 2012
    Posts:
    175
    http://gamedev.stackexchange.com/qu...el-shows-on-screen-when-object-is-out-of-view

    Fixed GUI issue with this
    Code (CSharp):
    1. void OnGUI()
    2.     {
    3.         InitStyles();
    4.  
    5.         // Draw a Health Bar
    6.         //   Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
    7.        
    8.         Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
    9.         if (Vector3.Angle(Camera.main.transform.forward, transform.position - Camera.main.transform.position) < 60)
    10.         {
    11.             // draw health bar background
    12.             GUI.color = Color.grey;
    13.             GUI.backgroundColor = Color.grey;
    14.             GUI.Box(new Rect(pos.x - 26, Screen.height - pos.y + 20, Combat.maxHealth / 2, 7), ".", backStyle);
    15.  
    16.             // draw health bar amount
    17.             GUI.color = Color.green;
    18.             GUI.backgroundColor = Color.green;
    19.             GUI.Box(new Rect(pos.x - 25, Screen.height - pos.y + 21, combat.health / 2, 5), ".", healthStyle);
    20.         }
    21.     }