I can't make work this 2 coroutines with their while loops!

Hey guys! Please help me with this… :frowning:

I’m trying to do something simple. A arrow button (GUItexture) which slides a menu when clicked and hide him back when clicked again. But I can only make the first coroutine to work. The else of OnMouseDown neither Debugs… The problem seems to be in the first while loop …

Please! :neutral:

using UnityEngine;
using System.Collections;

public class SetaMenuButton : MonoBehaviour {
	
	private Vector3 hidePosition = new Vector3(1.02f,0.87f,0f);
	private Vector3 showPosition = new Vector3(0.7f,0.87f,0f);
	private bool showMenu = true;
	public float smooth = 0.5f;

        void OnMouseDown(){
		if(showMenu){
		showMenu = false;
		Debug.Log ("showMenu" + showMenu);
		StartCoroutine("ShowMenu");
		} 
		else{
		showMenu = true;
		Debug.Log ("showMenu" + showMenu);
		StartCoroutine("HideMenu");
		}
	}
		
	IEnumerator ShowMenu(){
		while(Vector2.Distance(transform.position,showPosition) > 0.05f){
			transform.position = Vector3.Lerp(transform.position,showPosition, Time.deltaTime * smooth);
			yield return null;
		}
	}
	
	IEnumerator HideMenu(){
		while(Vector2.Distance(transform.position,hidePosition) > 0.05f){
			transform.position = Vector3.Lerp(transform.position,hidePosition, Time.deltaTime * smooth);
			yield return null;
		}
	}

}

Code tested, works exactly as expected
You might want to add
StopCoroutine( “HideMenu” );
and vice versa to each click, so they they can’t run at the same time

Ow! That’s whi i cound’t find a solution! LOL! Tanks! Seems like the button was hidden behind a guitext…

Thanks a lot for test my script! ;D