Complicated request for script/help/explanations etc.

Hi, i’m just going to jump right into it.

What i’m trying to do is create a script that will display a little texture that I made, which in other words is a little meter. The idea is a “Panic Meter” it’s complicated to explain because it goes more in depth with the game i’m making… But basically I want to have it be displayed on the bottom left of the screen, and every time the player enters a trigger zone with a specific tag, the meter texture will change to the other one(s) i’ve made. There’s 8 meters for 8 bars… And over time the meter will decrease by 1 bar for every 30 seconds (In other words, switching back one texture)
~
when the meter reaches 8 the player basically dies with a message or texture that pops up on the screen.

I know it sounds complicated or easy, i’ve tried to do this myself but I couldn’t do it at all… I don’t really know how to use floats as well as some other people. I’ve tried watching tutorials on how to use floats but they’re just way too complicated.

I’m willing to provide more information and reply to any answer/tip. Sorry if the post is too long or boring and loses your attention…

Something like this:

// C#
using UnityEngine;
using System.Collections;

public class PanicMeter : MonoBehaviour
{
	public float decayRate = 1.0f/30.0f; // one level every 30 seconds
	public Texture2D[] textures;
	private static float m_PanicLevel = 0;
	public static float PanicLevel
	{
		get { return m_PanicLevel;}
		set
		{
			// keep value above or equal to 0.0f
			m_PanicLevel = Mathf.Max(value, 0.0f);
		}
	}
	
	void Start()
	{
		useGUILayout = false;
		InvokeRepeating("Decay", 1.0f, 1.0f);
	}
	
	void Decay()
	{
		if (PanicLevel > 0)
			PanicLevel -= decayRate;
	}
	
	void OnGUI()
	{
		if (PanicLevel > 0)
		{
			int index = Mathf.Clamp((int)PanicLevel, 0, textures.Length);
			Texture2D tex = textures[index];
			Rect rect = new Rect(0, Screen.height-tex.height, tex.width, tex.height);
			GUI.DrawTexture(rect, tex);
		}
	}
}

You can simply use:

PanicMeter.PanicLevel++;

To increase the panic level by 1. Or set it to a certain level:

PanicMeter.PanicLevel = 5;

It will be automatically decreased. You just have to add your textures to the textures array (of course in the right order :wink: ).

You can attach another script to your trigger zones which will increase the panic level.