I created a new UI>Text object and named it ‘Player1Stamina’. This text is supposed to constantly display the value of the variable ‘stamina’ found in the script ‘player1Movement’.
The problem is I cannot get the text displayed during Play to say anything other than the line of placeholder text I put in the text field on the ‘Player1Stamina’ which is currently ‘Player 1 Stamina’.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class player1Movement : MonoBehaviour {
public Text Player1Stamina;
private int stamina;
int maxStamina;
int staminaRecharge;
bool staminaRecharging;
bool canMove;
void Start ()
{
maxStamina = 100;
stamina = 100;
SetStaminaText ();
staminaRecharge = 2;
staminaRecharging = true;
canMove = true;
}
void Update ()
{
if (staminaRecharging = true && stamina < maxStamina)
{
stamina += staminaRecharge;
SetStaminaText ();
}
if (Input.GetKey ("space"))
{
stamina -= (staminaRecharge * 5);
SetStaminaText ();
}
if (Input.GetKey ("z"))
{
stamina += (staminaRecharge);
SetStaminaText ();
}
}
void SetStaminaText ()
{
Player1Stamina.text = "Stamina: ";
}
}