WorldSpace HUD/GUI plus UFPS

This video shows how to create a HUD (Heads Up Display) in Unity 5.1 using VisionPunk’s UFPS asset and the newest Unity GUI.

UFPS
https://www.assetstore.unity3d.com/en/#!/content/2943

Script

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

namespace red
{
 public class red_HudWorldSpace : MonoBehaviour 
 {
 //Health Information
 public Text healthLabel=null;
 public Slider healthSlider=null;

 //Ammo Information
 public Text ammoLabel=null;
 //For Future Ammo - changes need to be made to UFPS scripts for the below to work
 //public RawImage ammoIcon=null;

 //UFPS Player
 protected vp_FPPlayerEventHandler m_Player=null;

 //SimpleHud - to turn on/off
 private vp_SimpleHUD m_Hud=null;
 public bool ShowSimpleHud=false; //On your 3rd person model, add this script but set the value in inspector to true

 void Start () 
 {
 m_Player = transform.GetComponentInParent<vp_FPPlayerEventHandler>();
 m_Hud = transform.GetComponentInParent<vp_SimpleHUD>();
 }
 
 // Update is called once per frame
 void Update () 
 {
 //Adjust the Health Text - using null, so that we can use the same script for 3rd person
 if(healthLabel!=null)
 healthLabel.text = (int)(m_Player.Health.Get()*10.0f) + "%";
 //Adjust the Health slider - using null, so that we can use the same script for 3rd person
 if(healthSlider!=null)
 healthSlider.value=m_Player.Health.Get()/10f;

 //Adjust the Ammo Text
 if(ammoLabel!=null)
 ammoLabel.text = (int)m_Player.CurrentWeaponAmmoCount.Get()+" / "+(int)m_Player.CurrentWeaponClipCount.Get();

 }
 void OnEnable()
 {
 if(m_Hud!=null)
 m_Hud.ShowHUD=ShowSimpleHud;
 }
 void OnDisable()
 {
 if(m_Hud!=null)
 m_Hud.ShowHUD=!ShowSimpleHud;
 }
 }
}

HeaderWP

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s