Premise:
I’ve got a button (made of a quad) working properly that references an animation curve to animate when clicked.
Issue
I can click my button once, and it’ll run through the coroutine that uses the animation curve to animate it. But after that, I can’t get it to trigger again. I know its still receiving the click events from the log, but the coroutine won’t run after the first time its run. Any ideas why? Code for the button script below:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Button : MonoBehaviour {
public AnimationCurve curveAnim;
public float posDisplacement;
public float speed;
public void KickBack(){
StartCoroutine (kickback());
}
IEnumerator kickback(){ //animation coroutine
float curveTime = 0f;
float curveAmount = curveAnim.Evaluate (curveTime);
while (curveAmount < 1.0f) {
curveTime += Time.deltaTime * speed;
curveAmount = curveAnim.Evaluate (curveTime);
transform.position = new Vector3 (transform.position.x, transform.position.y, curveAmount*posDisplacement);
yield return null;
}
}
//Button events called from "gameObject.SendMessage." in another script
void OnTouchDown(){
Debug.Log ("Touch Down!");
}
void OnTouchUp(){
Debug.Log ("Touch Up!");
KickBack ();
}
void OnTouchStay(){
}
void OnTouchExit(){
}
}