Hey guys! Please help me with this… ![]()
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;
}
}
}