Last active
August 3, 2016 04:55
-
-
Save sujoyu/90aa1cbcb3cf744b4cbe9f68650c50c3 to your computer and use it in GitHub Desktop.
A Simple unity script for modal dialogs on uGUI. When click outside the modal, close it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using UnityEngine.EventSystems; | |
using System.Linq; | |
public class Closer : MonoBehaviour, IPointerClickHandler { | |
public int ancestorLevel = 0; | |
public void OnPointerClick(PointerEventData data) { | |
var target = Enumerable.Range (0, ancestorLevel) | |
.Aggregate (gameObject.transform, (acc, _) => acc.transform.parent); | |
Destroy (target.gameObject); | |
data.Use (); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage