示例#1
0
 private void InteractionHandler(Vector2 directionVector2)
 {
     if (Physics2D.Raycast(transform.position, directionVector2, 1).collider.tag == "Interactable")
     {
         //This is the raycast
         RaycastHit2D raycast = Physics2D.Raycast(transform.position, directionVector2, 1);
         //grabs InteractBase script from object hit by raycast
         InteractBase interactScript = raycast.collider.GetComponent <InteractBase>();
         //Links interact script to the player
         interactScript.player = gameObject;
         //Runs interact scripts Interact() function
         interactScript.Interact();
     }
 }
示例#2
0
 private void HandleInput()
 {
     if (Input.GetButtonDown(ButtonsName.ButtonA))
     {
         var hits = Physics.RaycastAll(new Ray(transform.position, transform.forward), 10f, 1 << LayerMask.NameToLayer("Interaction"));
         if (hits != null && hits.Length > 0)
         {
             mInteractObj = hits[0].collider.gameObject.GetComponent <InteractBase>();
             if (mInteractObj != null)
             {
                 StartCoroutine(Resolve());
             }
         }
     }
 }