//do the physics calculation to check user is in contact with any kitchen stand void CheckForKitchenStands() { //RaycastHit hit; //var result = Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, contactDistance, kitchenStandLayer); //Debug.DrawRay(transform.position, result ? hit.transform.position : transform.forward, result ? Color.red : Color.green); var colliders = Physics.OverlapCapsule(transform.position + Vector3.down * characterController.height / 2, transform.position + Vector3.up * characterController.height / 2, characterController.radius, kitchenStandLayer); if (colliders?.Length > 0) { var kitchenStand = colliders[0].GetComponentInParent <KitchenStand>(); if (kitchenStand != null) { //Debug.Log("Kitchen Stand: " + hit.collider.name); if (!(currentStandInContact == null || currentStandInContact == kitchenStand)) { currentStandInContact.SetPlayerContactEnable(false); } else { kitchenStand.SetPlayerContactEnable(true); } currentStandInContact = kitchenStand; } } else { if (currentStandInContact != null) { currentStandInContact.SetPlayerContactEnable(false); currentStandInContact = null; } } }
private void OnTriggerExit(Collider other) { if (other.gameObject.layer == kitchenStandLayer) { currentStandInContact.SetPlayerContactEnable(false); currentStandInContact = null; } }