using UnityEngine; using System.Collections; public class ZRay : MonoBehaviour { private static ZRay instance; public static ZRay Instance { get { if (instance == null)instance = GameObject.FindObjectOfType<ZRay>() as ZRay; return instance; } } public delegate void RAY(GameObject obj); public event RAY rayEvent; Ray ray; RaycastHit hit; void Update() { ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { rayEvent(hit.collider.gameObject); } } }
using UnityEngine; using System.Collections; public class Do : MonoBehaviour { void Start() { ZRay.Instance.rayEvent += dosth; } void dosth(GameObject obj) { Debug.Log(obj.name); } }