- Home /
 
 
               Question by 
               freedom667 · Oct 30, 2015 at 09:14 PM · 
                unity 5menueventsystemmouseclickdropdown  
              
 
              how can do open and close click in UI.EventSystems
i did a dropdown menu from a youtube tutorial but she shows OnPointerEnter and OnPointerExit. i did one OnPointerClick for open but the function allows once. i want to do twice. when i click it will open, when i click again it will close. how can i do it??
The Script:
 using UnityEngine;
 using UnityEngine.EventSystems;
 using System.Collections;
 
 public class DropDown : MonoBehaviour, IPointerClickHandler, IPointerExitHandler{
 
     public RectTransform container;
     public bool isOpen;
 
     // Use this for initialization
     void Start () {
         container = transform.FindChild ("Container").GetComponent<RectTransform> ();
         isOpen = false;
     }
     
     // Update is called once per frame
     void Update () {
 
         Vector3 scale = container.localScale;
         scale.y = Mathf.Lerp (scale.y, isOpen ? 1 : 0, Time.deltaTime * 12);
         container.localScale = scale;
     }
 
     public void OnPointerClick(PointerEventData eventData)
     {
         isOpen = true;
     }
     public void OnPointerExit(PointerEventData eventData)
     {
         isOpen = false;
     }
 }
 
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by LovattoStudio · Oct 31, 2015 at 12:41 PM
 public void OnPointerClick(PointerEventData eventData)
      {
          isOpen = !isOpen;
      }
 
              Is that the actual Dropdown comonent source code? Where can I read components source code from?
That's not built in code. The OP is using the bool isOpen in his/her Update function to change the scale of the GameObject between 0 and 1. So changing the bool will take effect starting the next Update.
Your answer
 
             Follow this Question
Related Questions
New dropdown menu sample 3 Answers
Two dynamic dropdowns from one source list 0 Answers