Skip to content

Instantly share code, notes, and snippets.

@jcowen-Berklee
Forked from lena3rika/Dropdown.cs
Created December 2, 2015 05:41
Show Gist options
  • Select an option

  • Save jcowen-Berklee/59e23a33febe522dfc74 to your computer and use it in GitHub Desktop.

Select an option

Save jcowen-Berklee/59e23a33febe522dfc74 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class Dropdown : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
public RectTransform container;
public bool isOpen;
public Text mainText;
public Image image { get { return GetComponent<Image>(); } }
void Start()
{
container = transform.FindChild("Container").GetComponent<RectTransform>();
isOpen = false;
}
public void Update()
{
Vector3 scale = container.localScale;
scale.y = Mathf.Lerp(scale.y, isOpen ? 1 : 0, Time.deltaTime * 10);
container.localScale = scale;
}
public void OnPointerEnter(PointerEventData eventData)
{
isOpen = true;
}
public void OnPointerExit(PointerEventData eventData)
{
isOpen = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment