private void handleInteraction() { Debug.Log("Trying to attach to game object"); Vector2 travelDirection = new Vector2(1, 0); if (!_facingRight) { travelDirection.x *= -1; } var radius = 2.0f; Collider2D hit = Physics2D.OverlapCircle(_transform.position, radius, _interactableLayer); if (hit == null) { return; } SetState(PlayerState.INTERACTING); _rigidbody.velocity = Vector2.zero; _rigidbody.isKinematic = true; Debug.Log($"Gameobject hit is {hit.gameObject.name}"); _interactingObject = hit.gameObject.GetComponent <IInteractableObject>(); if (_interactingObject.CanInteract(InteractableType.GEAR)) { head.StartInteraction(_interactingObject); } else if (_interactingObject.CanInteract(InteractableType.POWER)) { // } // RaycastHit2D hit = Physics2D.Raycast(_transform.position, travelDirection, 2.0f, _interactableLayer); // if (hit.collider != null) { // _interactingObject = hit.collider.gameObject.GetComponent<IInteractableObject>(); // } }
private void handleReleaseInput() { if (_interactingObject.CanInteract(InteractableType.GEAR)) { head.EndInteraction(); } else if (_interactingObject.CanInteract(InteractableType.POWER)) { } _interactingObject = null; _rigidbody.isKinematic = false; SetState(PlayerState.ACTIVE); }