Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    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.     }