// Update is called once per frame void Update() { if (isInvincible) { timer -= Time.deltaTime; if (timer <= 0) { isInvincible = false; } } if (Input.GetKeyDown(KeyCode.C)) { Shoot(); } if (Input.GetKeyDown(KeyCode.X)) { //Raycast hit store result from Physic2D.raycast RaycastHit2D hit = Physics2D.Raycast(rigidbody2.position + Vector2.up * 0.5f, //Ruby;s position from the center of the body direction, //the direction for the ray to go 1.5f, // the ray's max lenght LayerMask.GetMask("NPC") //the targeted layers to return result ); if (hit.collider != null) { Debug.Log("Cast hit: " + hit.collider.gameObject); NPC npc = hit.collider.GetComponent <NPC>(); if (npc != null) { npc.ActivateDialog(); } } } }