I have a controller script that controls a stamina bar…
using UnityEngine;
using System.Collections;
public class StaminaScript : MonoBehaviour {
public Texture2D staminaGuiTex;
public Texture2D staminaBlueTex;
public float currTime;
public static float staminaScale;
// Use this for initialization
void Awake () {
currTime = Time.time;
staminaScale = 221;
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.LeftShift) | Input.GetKey (KeyCode.RightShift)){
if(currTime < Time.time){
if(staminaScale != 0){
staminaScale -= 0.25f;
}
currTime = Time.time;
}
}
}
public void OnGUI() {
GUI.DrawTexture(new Rect(Screen.width - 300, 94, 256, 64), staminaGuiTex, ScaleMode.StretchToFill, true, 0);
GUI.DrawTexture(new Rect(Screen.width - 283, 116, staminaScale, 18), staminaBlueTex, ScaleMode.StretchToFill, true, 0);
}
}
and I need this script to change add to it after the victim is attacked…
<if (((num <= this.biteDistance) && Input.GetButtonDown("Jump")) || (num2 <= this.biteDistance))
{
GUIKills.numberOfKills++;
StaminaScript.staminaScale = (StaminaScript.staminaScale + 221 * (25/221));
this.status = AIStatus.Attacked;
However, no matter if I use a static variable or not, no error messages appear, but the staminaScale variable doesn’t update. Any suggestions?
EDIT: There is a third Script I try to change the variable and it works…
enter code herevoid Update ()
{
if(!died&&(GameController.health <= 0))
{
//StaminaScript staminaScript = GameObject.FindGameObjectWithTag("Stam").GetComponent<StaminaScript>();
StaminaScript.staminaScale = 221;
Die();
}
if(Input.GetButtonDown("Jump"))
{
gameObject.audio.PlayOneShot(audio.clip);
}
}