I have this code that makes plants move as the player walks past them (like they just jiggle a little) but for some reason it only works once and then when the player walks past them again, nothing happens… is it something in my code?
private Animator anim;
private IEnumerator coroutine;
void Start()
{
anim = GetComponent<Animator>();
coroutine = Wobble();
}
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Player"))
{
StartCoroutine(coroutine);
}
}
IEnumerator Wobble()
{
anim.SetBool("move", true);
yield return new WaitForSeconds(0.5f);
anim.SetBool("move", false);
yield return new WaitForSeconds(0f);
}