using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BNG {
///
/// Keeps a List of all Grabbers within this Trigger
///
public class GrabberArea : MonoBehaviour {
public Grabber InArea;
public List grabbersInArea;
private void Update() {
InArea = GetOpenGrabber();
}
public Grabber GetOpenGrabber() {
if(grabbersInArea != null && grabbersInArea.Count > 0) {
foreach (var g in grabbersInArea) {
if(!g.HoldingItem) {
return g;
}
}
}
return null;
}
void OnTriggerEnter(Collider other) {
Grabber grab = other.GetComponent();
if (grab != null) {
if(grabbersInArea == null) {
grabbersInArea = new List();
}
if(!grabbersInArea.Contains(grab)) {
grabbersInArea.Add(grab);
}
}
}
void OnTriggerExit(Collider other) {
Grabber grab = other.GetComponent();
if (grab != null) {
if (grabbersInArea == null) {
return;
}
if (grabbersInArea.Contains(grab)) {
grabbersInArea.Remove(grab);
}
}
}
}
}