void OnTriggerExit(Collider col) { Transform grabable = col.FindAncestorOrSelf((t) => t.gameObject.layer == LayerMask.NameToLayer(Layers.GRABABLE)); if(grabable != null) { exitCount++; int count; if(grabablesInRange.TryGetValue(grabable.gameObject, out count)) { if(count == 1) { grabablesInRange.Remove(grabable.gameObject); } else { grabablesInRange[grabable.gameObject] = count - 1; } } } }
void OnTriggerEnter(Collider col) { Transform colGrabable = col.FindAncestorOrSelf((t) => t.IsActiveGrabable()); if(colGrabable != null) { enterCount++; int count; if(grabablesInRange.TryGetValue(colGrabable.gameObject, out count)) { grabablesInRange[colGrabable.gameObject] = count + 1; } else { grabablesInRange.Add(colGrabable.gameObject, 1); } } }