I"m trying to get that the player can no longer pause when the ManaBar is empty. But I just can’t seem to get a script in my mind for it…
Here’s the Pausing script:
using UnityEngine;
using System.Collections;
public class Freeze : MonoBehaviour {
public int p = 0;
private GameObject target;
public void Start() {
target = GameObject.FindGameObjectWithTag("player");
}
public void Update () {
AddjustCurrentfreeze(0);
}
public void AddjustCurrentfreeze(int adj) {
p += adj;
if (Input.GetKeyDown(KeyCode.P))
{
if (p == 0)
{
Time.timeScale=0;
Screen.showCursor = true;
Screen.lockCursor = false;
p = 1;
PlayerManaBar eh = (PlayerManaBar)target.GetComponent("PlayerManaBar");
eh.AddjustCurrentMana(-100);
}
else
{
Time.timeScale=1.0f;
p=0;
}
}
}
}
Here’s the ManaBar script :
using UnityEngine;
using System.Collections;
public class PlayerManaBar : MonoBehaviour {
public GameObject target;
GUIStyle style = new GUIStyle();
Texture2D texture;
Color yeColor = Color.yellow;
Color cyanColor = Color.cyan;
private int curMana = 1000;
private int maxMana = 1000;
void Start()
{
texture = new Texture2D(1, 1);
texture.SetPixel(1, 1, cyanColor);
}
void Update()
{
AddjustCurrentMana(0);
}
public void AddjustCurrentMana(int adj) {
curMana += adj;
if(curMana < 0)
{
curMana = 0;
}
if(curMana > maxMana)
{
curMana = maxMana;
}
if(maxMana < 1)
{
maxMana = 1;
}
if (curMana <= 1000)
{
texture.SetPixel(1, 1, cyanColor);
}
}
public void OnGUI()
{
texture.Apply();
style.normal.background = texture;
GUI.Box(new Rect(10, 40, curMana, 20), new GUIContent(""), style);
GUI.Box(new Rect(10, 40, 1000, 20), "");
}
}
its supposed to be if (curMana == 0) { p=0; }
– spiralfire11