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. Dismiss Notice

How to create a VR Health Bar?

Discussion in 'AR/VR (XR) Discussion' started by SonEvil, Sep 15, 2015.

  1. SonEvil

    SonEvil

    Joined:
    Jul 29, 2015
    Posts:
    11
    as the title, someone please help me ?

    My Health Script :

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var Health = 100;
    4.  
    5. function ApplyDammage (TheDammage : int)
    6. {
    7.     Health -= TheDammage;
    8.    
    9.     if(Health <= 0)
    10.     {
    11.         Dead();
    12.     }
    13. }
    14.  
    15. function Dead()
    16. {
    17.     Destroy (gameObject);
    18. }
     
  2. HankySpanky

    HankySpanky

    Joined:
    Feb 3, 2015
    Posts:
    77
    I'm pretty curious about this as well. Or how you'd use the new UI system that was introduced in 4.6 with VR.

    It can't be that hard to adjust a normal UI for VR can it?
     
  3. Tapgames

    Tapgames

    Joined:
    Dec 1, 2009
    Posts:
    242
    U have to set the UI to "world space" and give the UI a nice place in the scene. :)
     
  4. Khyrid

    Khyrid

    Joined:
    Oct 8, 2010
    Posts:
    1,790
    So far I tried;

    GUI: Doesn't work in VR

    Canvas:
    Great for everything except anything that needs to be animated or change a lot. You can't just draw your health bar to a canvas texture the same way you would with GUI. You could make a bunch of little textures and have them disable and enable based on player health.

    Planes and geometry: I like just slapping planes as children to the VR cam and controlling if they are visible or not with scripts. It's very simplistic, such as the canvas example above. I built my main menu this way a long time ago and after making the project VR, I found that it works very well.

    Render to Texture: I haven't figured out how to use this or what it does.
     
  5. Selzier

    Selzier

    Joined:
    Sep 23, 2014
    Posts:
    652
    What's wrong with a method like this?
     
    Khyrid likes this.