I have a script that functions as the player’s stamina bar. Here’s that…
#pragma strict
var staminaBar : GameObject;
var fadeTime : float = 0.20763;
var timerSpeed : float = 0;
var startPosition : float = 0;
var endPosition : float = 0;
var jumpStamina : float = 0;
var sprintTrigger : GameObject;
var staminaTimer : Light;
var player : CharacterController;
function Start ()
{
staminaBar.GetComponent.<RectTransform>().anchoredPosition.x = startPosition;
}
function Update ()
{
if (Input.GetButton("Sprint") && Input.GetAxis("Horizontal") || Input.GetButton("Sprint") && Input.GetAxis("Vertical"))
if (staminaBar.GetComponent.<RectTransform>().anchoredPosition.x < endPosition)
if (player.isGrounded)
{
staminaBar.GetComponent.<RectTransform>().anchoredPosition.x += 0.1 * Time.deltaTime / fadeTime;
}
if (sprintTrigger.activeSelf)
if (staminaBar.GetComponent.<RectTransform>().anchoredPosition.x > startPosition)
if(staminaTimer.GetComponent.<Light>().intensity == 0)
{
staminaBar.GetComponent.<RectTransform>().anchoredPosition.x -= 0.1 * Time.deltaTime / fadeTime;
}
if (Input.GetButton("Sprint") && Input.GetAxis("Horizontal") || Input.GetButton("Sprint") && Input.GetAxis("Vertical"))
{
sprintTrigger.SetActive (false);
}
else
{
sprintTrigger.SetActive (true);
}
if (Input.GetButtonDown("Jump"))
if (player.isGrounded)
if (staminaBar.GetComponent.<RectTransform>().anchoredPosition.x < endPosition)
{
staminaBar.GetComponent.<RectTransform>().anchoredPosition.x += jumpStamina;
}
if (staminaBar.GetComponent.<RectTransform>().anchoredPosition.x == endPosition)
{
staminaTimer.GetComponent.<Light>().intensity = 8;
}
staminaTimer.GetComponent.<Light>().intensity -= 0.1 * Time.deltaTime / timerSpeed;
}
I am having one issue though. The last statement isn’t working. The one where I want the intensity of the light to change to 8. I’m not sure why that is…
if (staminaBar.GetComponent.<RectTransform>().anchoredPosition.x == endPosition)
{
staminaTimer.GetComponent.<Light>().intensity = 8;
}
Why is this not working?