using System.Collections.Generic; using UnityEngine; public class P_InteractCollision : MonoBehaviour { private bool SuccessfulInteraction; private List ListOfInteractables = new List(); private void OnTriggerEnter2D(Collider2D other) { if ((bool)other.GetComponent()) { ListOfInteractables.Add(other.GetComponent()); } if ((bool)other.GetComponent()) { ListOfInteractables.Add(other.GetComponent()); } if ((bool)other.GetComponent()) { ListOfInteractables.Add(other.GetComponent()); } if ((bool)other.GetComponent()) { ListOfInteractables.Add(other.GetComponent()); } if ((bool)other.GetComponent()) { ListOfInteractables.Add(other.GetComponent()); } if ((bool)other.GetComponent()) { ListOfInteractables.Add(other.GetComponent()); } if ((bool)other.GetComponent()) { ListOfInteractables.Add(other.GetComponent()); } if ((bool)other.GetComponent()) { ListOfInteractables.Add(other.GetComponent()); } Component component = null; float num = float.PositiveInfinity; foreach (Component listOfInteractable in ListOfInteractables) { if (Vector2.Distance(PlayerManager.Instance.transform.position, listOfInteractable.transform.position) < num) { component = listOfInteractable; } } if (component != null) { if (component.GetType() == typeof(INT_Chat) && !SuccessfulInteraction) { component.GetType().GetMethod("RUN").Invoke(component, null); SuccessfulInteraction = true; } if (component.GetType() == typeof(INT_Generic) && !SuccessfulInteraction) { component.GetType().GetMethod("Interact").Invoke(component, null); SuccessfulInteraction = true; } if (component.GetType() == typeof(INT_ChangeBool) && !SuccessfulInteraction) { component.GetType().GetMethod("RUN").Invoke(component, null); SuccessfulInteraction = true; } if (component.GetType() == typeof(INT_ChangePlayerVariable) && !SuccessfulInteraction) { component.GetType().GetMethod("RUN").Invoke(component, null); SuccessfulInteraction = true; } if (component.GetType() == typeof(INT_DestroyComponent) && !SuccessfulInteraction) { component.GetType().GetMethod("RUN").Invoke(component, null); SuccessfulInteraction = true; } if (component.GetType() == typeof(INT_PlaySound) && !SuccessfulInteraction) { component.GetType().GetMethod("RUN").Invoke(component, null); SuccessfulInteraction = true; } if (component.GetType() == typeof(INT_EnableGameObject) && !SuccessfulInteraction) { component.GetType().GetMethod("RUN").Invoke(component, null); SuccessfulInteraction = true; } if (component.GetType() == typeof(INT_SaveInt) && !SuccessfulInteraction) { component.GetType().GetMethod("RUN").Invoke(component, null); SuccessfulInteraction = true; } } ListOfInteractables.Clear(); SuccessfulInteraction = false; } }