So heres what im trying to do, i have a cursor set up, that animates when it collides with certain objects. the cursor plays an animation (to show that your selecting the object) for two seconds. after two seconds that object will be selected. If in that two seconds, the player decides they dont want to select that object, and they move the curso off, the animation should stop playing, and the object should not be selected. I have the animation set up in a Coroutine which is called in an OnTriggerEnter Function, then i have a StopCoroutine call in the OnTriggerExit function. when the player moves the cursor away, the animation stops playing and the curosr goes back to normal. The problem i am having is that after two seconds, the object still gets selected. Any ideas how i can fix this? heres my code
public bool enumBool = false;
private bool waitBool = true;
void OnTriggerEnter(Collider col)
{
if (col.gameObject.name.Contains ("Arrow")) {
Orbit.isMoving = false;
StartCoroutine(WAIT());
if (col.gameObject.name.Contains ("Up")) {
col.gameObject.transform.GetChild (0).transform.GetComponent<ChangeLabelColor> ().changeColor ();
if (enumBool == true){
StartCoroutine(moveThumbnailsUp());
}
}
if (col.gameObject.name.Contains ("Down")) {
col.gameObject.transform.GetChild (0).transform.GetComponent<ChangeLabelColorDOWN> ().changeColor ();
if (enumBool == true)
{
StartCoroutine(moveThumbnailsDown());
}
}
}
void OnTriggerExit(Collider col)
{
enumBool = false;
StopCoroutine (WAIT());
}
IEnumerator WAIT(){
waitBool = true;
transform.parent.GetComponent<changeCursor>().hideCursor();
transform.parent.GetComponent<changeCursor>().playAnimation();
enumBool = true;
yield return new WaitForSeconds(2);
transform.parent.GetComponent<changeCursor> ().goBackNormal ();
waitBool = false;
}
IEnumerator moveThumbnailsDown()
{
while (waitBool)
yield return new WaitForSeconds (0.1f);
Debug.Log ("MOVING DOWN");
transform.parent.GetComponent<changeCursor>().goBackNormal();
thumbnail1.GetComponent<Orbit> ().canMoveUp = true;
thumbnail2.GetComponent<Orbit> ().canMoveUp = true;
thumbnail3.GetComponent<Orbit> ().canMoveUp = true;
thumbnail4.GetComponent<Orbit> ().canMoveUp = true;
thumbnail5.GetComponent<Orbit> ().canMoveUp = true;
thumbnail6.GetComponent<Orbit> ().canMoveUp = true;
thumbnail7.GetComponent<Orbit> ().canMoveUp = true;
thumbnail8.GetComponent<Orbit> ().canMoveUp = true;
thumbnail9.GetComponent<Orbit> ().canMoveUp = true;
thumbnail10.GetComponent<Orbit> ().canMoveUp = true;
thumbnail11.GetComponent<Orbit> ().canMoveUp = true;
thumbnail12.GetComponent<Orbit> ().canMoveUp = true;
thumbnail13.GetComponent<Orbit> ().canMoveUp = true;
thumbnail14.GetComponent<Orbit> ().canMoveUp = true;
thumbnail15.GetComponent<Orbit> ().canMoveUp = true;
thumbnail16.GetComponent<Orbit> ().canMoveUp = true;
thumbnail17.GetComponent<Orbit> ().canMoveUp = true;
thumbnail18.GetComponent<Orbit> ().canMoveUp = true;
thumbnail19.GetComponent<Orbit> ().canMoveUp = true;
thumbnail20.GetComponent<Orbit> ().canMoveUp = true;
thumbnail21.GetComponent<Orbit> ().canMoveUp = true;
thumbnail22.GetComponent<Orbit> ().canMoveUp = true;
thumbnail23.GetComponent<Orbit> ().canMoveUp = true;
thumbnail24.GetComponent<Orbit> ().canMoveUp = true;
enumBool = false;
}
IEnumerator moveThumbnailsUp()
{
while (waitBool)
yield return new WaitForSeconds (0.1f);
Debug.Log ("MOVINGUP");
transform.parent.GetComponent<changeCursor>().goBackNormal();
thumbnail1.GetComponent<Orbit> ().canMoveDown = true;
thumbnail2.GetComponent<Orbit> ().canMoveDown = true;
thumbnail3.GetComponent<Orbit> ().canMoveDown = true;
thumbnail4.GetComponent<Orbit> ().canMoveDown = true;
thumbnail5.GetComponent<Orbit> ().canMoveDown = true;
thumbnail6.GetComponent<Orbit> ().canMoveDown = true;
thumbnail7.GetComponent<Orbit> ().canMoveDown = true;
thumbnail8.GetComponent<Orbit> ().canMoveDown = true;
thumbnail9.GetComponent<Orbit> ().canMoveDown = true;
thumbnail10.GetComponent<Orbit> ().canMoveDown = true;
thumbnail11.GetComponent<Orbit> ().canMoveDown = true;
thumbnail12.GetComponent<Orbit> ().canMoveDown = true;
thumbnail13.GetComponent<Orbit> ().canMoveDown = true;
thumbnail14.GetComponent<Orbit> ().canMoveDown = true;
thumbnail15.GetComponent<Orbit> ().canMoveDown = true;
thumbnail16.GetComponent<Orbit> ().canMoveDown = true;
thumbnail17.GetComponent<Orbit> ().canMoveDown = true;
thumbnail18.GetComponent<Orbit> ().canMoveDown = true;
thumbnail19.GetComponent<Orbit> ().canMoveDown = true;
thumbnail20.GetComponent<Orbit> ().canMoveDown = true;
thumbnail21.GetComponent<Orbit> ().canMoveDown = true;
thumbnail22.GetComponent<Orbit> ().canMoveDown = true;
thumbnail23.GetComponent<Orbit> ().canMoveDown = true;
thumbnail24.GetComponent<Orbit> ().canMoveDown = true;
enumBool = false;
}