Skip to content

Instantly share code, notes, and snippets.

@lena3rika
Created August 30, 2015 15:00
Show Gist options
  • Save lena3rika/df7ca76fe0e28343d6a2 to your computer and use it in GitHub Desktop.
Save lena3rika/df7ca76fe0e28343d6a2 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