Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class DetectorS : MonoBehaviour {
- [Header("Info")]
- public List<GameObject> detected;
- [Header("Options")]
- public List<string> tagsToDetect;
- // COMPONENTS
- private SphereCollider sc;
- // EVENTS
- public delegate void EventHandler(DetectorS detectorS, GameObject detectedGO);
- public event EventHandler DetectedSomething, UndetectedSomething;
- void OnTriggerEnter(Collider collider)
- {
- if (!tagsToDetect.Contains(collider.tag)) return;
- Detect(collider.gameObject);
- }
- void OnTriggerExit(Collider collider)
- {
- if (!tagsToDetect.Contains(collider.tag)) return;
- Undetect(collider.gameObject);
- }
- void Detect(GameObject go)
- {
- if (detected.Contains(go)) return;
- // ADD
- detected.Add(go);
- // EVENT
- if (DetectedSomething != null) DetectedSomething(this, go);
- }
- void Undetect(GameObject go)
- {
- if (!detected.Contains(go)) return;
- // REMOVE
- detected.Remove(go);
- // EVENT
- if (UndetectedSomething != null) UndetectedSomething(this, go);
- }
- }
Add Comment
Please, Sign In to add comment