Hi,how to optimize this C# script,looks like mess to me. + doesn’t work as it should;
if it’s not that messy,how can i check if i have more than 5 manapoints? because now when i press B,nothing happens,…++ if i try to write Mana.baterieSlider.value = currentMana to update its says not in current context…
private AudioSource source;
public AudioClip hasteSound;
public float countdown = 0;
public float AirBasic = 30;
public float currentMana = 0;
bool isHaste;
void Awake()
{
GameObject thePlayer = GameObject.Find ("Player");
PlayerVitals Mana = thePlayer.GetComponent<PlayerVitals> ();
Mana.baterieSlider.value = currentMana;
source = GetComponent<AudioSource> ();
}
void Update () {
if (Input.GetKeyUp (KeyCode.B)&& !isHaste&& currentMana > 5)
{
GameObject thePlayer = GameObject.Find ("Player");
PlayerVitals Mana = thePlayer.GetComponent<PlayerVitals> ();
inventory moveSpeed = thePlayer.GetComponent<inventory> ();
isHaste = true;
countdown = AirBasic;
moveSpeed.speed += 1;
Mana.baterieSlider.value -= 5;
source.PlayOneShot (hasteSound, 0.9f);
}
if (isHaste == true)
{
countdown -= Time.deltaTime;
}
if (countdown <= 0)
{
//countdown = 0;
isHaste = false;
GameObject thePlayer = GameObject.Find ("Player");
inventory moveSpeed = thePlayer.GetComponent<inventory> ();
moveSpeed.speed = 4;
}
}
}