void GetAllPossibleActions(List <GameAction> possibleActions) { Collider[] colliders = Physics.OverlapSphere(transform.position, interactionRadius, interactionLayers); foreach (var c in colliders) { InteractiveObject interactiveObject = c.GetComponentInChildren <InteractiveObject>(); if (interactiveObject == null) { interactiveObject = c.GetComponentInParent <InteractiveObject>(); } if (interactiveObject != null) { if (!interactiveObject.enabled) { continue; } Vector3 playerPos = transform.position + Vector3.up * 1.8f; Vector3 objectPos = interactiveObject.GetCenter(); Vector3 toInteractive = objectPos - playerPos; Ray ray = new Ray(playerPos, toInteractive.normalized); bool collision = false; RaycastHit[] hits = Physics.RaycastAll(ray, toInteractive.magnitude, environmentMask); foreach (var hit in hits) { collision = true; } if (!collision) { // Get all possible actions GameAction[] actions = interactiveObject.GetComponentsInChildren <GameAction>(); foreach (var a in actions) { if (a.enabled) { possibleActions.Add(a); } } } } } }