private void ListenInteractByMouseClick() { if (Input.GetButtonDown("Fire1")) { RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1f, LayerMask.GetMask("Consumable")); if (hit.collider != null) { Debug.Log("Raycast has hit the object " + hit.collider.gameObject); ConsumableBehaviour littleMan = hit.collider.GetComponent <ConsumableBehaviour>(); if (littleMan != null) { littleMan.Kill(); } } } }
private void ListenInteractByKeyPress() { if (Input.GetKeyDown(KeyCode.C)) { var nearestTransform = Helper.GetClosestTransform(TriggerZone.GetListOfTriggerTransforms(), transform); if (nearestTransform.CompareTag("Consumable")) { Debug.Log("Hitted : " + nearestTransform.name); ConsumableBehaviour littleMan = nearestTransform.GetComponent <ConsumableBehaviour>(); if (littleMan != null) { littleMan.Kill(); } } else if (nearestTransform.CompareTag("Enemy")) { Debug.Log("This is enemy"); } } }