Hello I am stumped on why my scripts won’t behave the way I imagine it should. I am trying to make a game where a player can use a special attack only when indicated by an orange bar that fills up to 100 percent. This bar fills up and stops at 100 percent as expected but when I go to press the right mouse button, which I made the designated button to press when it is full, it does not become zero and I am able to still use the special attack when I shouldn’t be. Also to note I am still able to cast the special attack even BEFORE the bar fills up which is boggling me.
To show an image of what it looks like here is an example
ALSO noted that the orange bar is rotated 90 degrees to face upward, as to avoid the confusion when you look into the script and it being locally scaled in the X axis.
Here is the script that I am trying to make this happen:
using UnityEngine;
using System.Collections;
public class AlternateAttackProtocol : MonoBehaviour
{
private static AlternateAttackProtocol instance = null;
public static AlternateAttackProtocol Instance
{
get {return instance; }
}
public Transform alternateAttackDisplay;
public float maxAlternateAttack = 100.0f;
public float currentAlternateAttack;
private float alternateAttackOriginalXScale;
void Start ()
{
alternateAttackOriginalXScale = alternateAttackDisplay.localScale.x;
currentAlternateAttack = 0.0f;
}
void Update ()
{
AlternateAttackTimer();
AlternateAttackButton();
}
void AlternateAttackTimer()
{
if(currentAlternateAttack <= 100)
{
Debug.Log("Being Accessed");
currentAlternateAttack = currentAlternateAttack + 0.5f;
alternateAttackDisplay.localScale = new Vector3(alternateAttackOriginalXScale * (currentAlternateAttack/maxAlternateAttack), alternateAttackDisplay.localScale.z, alternateAttackDisplay.localScale.z);
}
}
void AlternateAttackButton()
{
if (currentAlternateAttack == 100 && Input.GetButtonDown ("Fire2"))
{
currentAlternateAttack = 0.0f;
}
}
}
If people could give me advise on how to do this that would be awesome.