- Home /
Switching abilitys too fast
So ive been writing my lil script , and i want my character to do a certain ability , depending on wich one is show'd on the botomleft of the screen
i want my character to be able to browse tho the ability by pressing TAB , and use the ability by pressing my Ability input button
Heres the script
using UnityEngine;
using System.Collections;
public class Ability : MonoBehaviour {
private GUIStyle rocketJumpGUI;
private GUIStyle sprintGUI;
private GUIStyle jetpackGUI;
public int rocketJumpCharge;
public float sprintEnergie;
public float jetpackFuel;
public bool rocketBool;
public bool sprintBool;
public bool jetpackBool;
public int cnt; // switch variable
// Use this for initialization
void Start () {
cnt = 0;
}
// Update is called once per frame
void Update () {
if (cnt == 0)
rocketJumpAbility();
if (cnt == 1)
sprintAbility();
if (cnt == 2)
jetpackAbility();
}
/// <summary>
/// Rocket Jump Ability
/// </summary>
public void rocketJumpAbility(){
if(Input.GetButtonUp("Ability") && cnt == 0)
{
Debug.Log("RocketJump Button Pressed");
if(rocketJumpCharge > 0)
{
// ACTION HERE
rocketJumpCharge--;
}
}
if (Input.GetKey ("tab") && cnt == 0)
{
cnt++;
}
}
/// <summary>
/// Sprint Ability
/// </summary>
public void sprintAbility(){
if(Input.GetButtonUp("Ability") && cnt == 1)
{
Debug.Log("Sprint Button Pressed");
if(sprintEnergie > 0) ;
// ACTION HERE REMOVE THIS ^
}
if (Input.GetKey ("tab") && cnt == 1)
{
cnt++;
}
}
/// <summary>
/// Jet Pack Ability
/// </summary>
public void jetpackAbility(){
if(Input.GetButtonUp("Ability") && cnt == 2)
{
Debug.Log("jetpack Button Pressed");
if(jetpackFuel > 0) ;
// ACTION HERE REMOVE THIS ^
}
if(Input.GetKey("tab") && cnt == 2)
{
cnt = 0;
}
}
private void displayGUI(){
}
}
What it does right now is , when i hit (AbilityInput) for the first time , it shows rocketjump , when i hit tab and then perss (AbilityInput) again , it shows rocketjump still , if i hold tab and hit (AbilityInput) , it'll show me all the abilitys
Your answer
Follow this Question
Related Questions
Toggle GUI button 1 Answer
Multiple Camera.main.ScreenPointToRay 1 Answer
Changing player model with keypress. 3 Answers
How to turn on a light, then off with the same button. 1 Answer
Switching Between Weapons? 1 Answer