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.
 
 

44 lines
939 B

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class BaseTrigger : MonoBehaviour {
public Circuit Circuit { get; private set; }
private readonly List<GameObject> colliders = new List<GameObject>();
void Awake() {
Circuit = GetComponentInParent<Circuit>();
}
private void OnMouseEnter() {
if (EventSystem.current) {
if (!EventSystem.current.IsPointerOverGameObject())
Circuit.OnMouseEnter();
}
}
private void OnMouseExit() {
Circuit.OnMouseExit();
}
private void OnCollisionEnter(Collision collision) {
if (Circuit.isDragged) {
colliders.Add(collision.gameObject);
if (colliders.Count == 1)
Circuit.OnCollisionEnter();
}
}
private void OnCollisionExit(Collision collision) {
if (Circuit.isDragged) {
colliders.Remove(collision.gameObject);
if (colliders.Count == 0)
Circuit.OnCollisionExit();
}
}
}