Tuesday, 4 March 2014

Flashlight HUD

Below is the C# sharp code I used to create the HUD for the flashlight. This code will display the flashlights remaining power out of 100, which will only show when a flashlight is collected, and below the number of batteries held will be shown:

using UnityEngine;
using System.Collections;

public class HUD : MonoBehaviour
{
public static int BatteryCount;
public static bool HasFlashlight;

void OnGUI()
{
if (HasFlashlight)
{
GUI.Label (new Rect (10, 10, 80, 30), "Flashlight");
GUI.Label (new Rect (70, 10, 80, 30), Flashlight.BatteryLife.ToString ("F2"));
}
GUI.Label (new Rect (10, 40, 80, 30), "Batteries");
GUI.Label (new Rect (70, 40, 80, 30), BatteryCount.ToString ());
}
}

No comments:

Post a Comment