You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
787 B
33 lines
787 B
10 years ago
|
using UnityEngine;
|
||
|
using UnityEngine.Events;
|
||
|
using System.Collections;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
|
/**
|
||
|
* Detects mouse clicks and touches on a Game Object, and sends an event to all Fungus Script event handlers in the scene.
|
||
|
* The Game Object must have a Collider2D component attached.
|
||
|
* Use in conjunction with the ObjectClicked Fungus Script event handler.
|
||
|
*/
|
||
|
public class Clickable2D : MonoBehaviour
|
||
|
{
|
||
|
[Tooltip("Is object clicking enabled")]
|
||
|
public bool clickEnabled = true;
|
||
|
|
||
|
void OnMouseDown()
|
||
|
{
|
||
|
if (!clickEnabled)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// TODO: Cache these object for faster lookup
|
||
|
ObjectClicked[] handlers = GameObject.FindObjectsOfType<ObjectClicked>();
|
||
|
foreach (ObjectClicked handler in handlers)
|
||
|
{
|
||
|
handler.OnObjectClicked(this);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|