I have an animation that changes my in game currency text to green but for some reason I cant get it to work? Probably an easy fix that I cant see, so help would be appreciated greatly!
public Text currencyText;
public int currency;
//Animations
public Animation addCurrencyAnim;
void Awake()
{
currency = 500;
addCurrencyAnim.enabled = false;
}
void Update()
{
currencyText.text = currency.ToString();
if (Input.GetKeyDown(KeyCode.UpArrow))
{
currency += 50;
addCurrencyAnim.enabled = true;
}
}
I think you have to use Anim.Play();
Haven’t tried just using an animation like that, though.
You would also need to drag the animation onto the variable in the editor, of course.
Seems to be working like that but if I spam the key then it doesnt play everytime I press that key only when it has stopped playing and then plays again
Under the Animator what are you using for a parameter? If it is a trigger you could reference your Animator and replace your:
addCurrencyAnim.enabled = true;
with something like this:
<Animator>.SetTrigger("<string_param_name>");
if it’s a bool use SetBool; take a look at this SetBool example:
Unless you want it to loop (a lot) when you have the key down you might want to change your logic there and disable the Loop for the Animation in your Projects folder.