Exemple #1
0
 void Interact(InputAction.CallbackContext context)
 {
     if (context.phase == InputActionPhase.Performed)
     {
         //Debug.Log("cam");
         //Debug.Log(cam.transform.position.x);
         var mousePOS = Input.mousePosition;
         mousePOS.z = 10;
         Vector3 worldPoint = cam.ScreenToWorldPoint(mousePOS);
         Vector2 wp2d       = new Vector2(worldPoint.x, worldPoint.y);
         Debug.Log("WP");
         Debug.Log(wp2d.x);
         Debug.Log(wp2d.y);
         RaycastHit2D hit = Physics2D.Raycast(wp2d, Vector2.zero, 1.0f, layer);
         if (hit)
         {
             Debug.Log(hit.transform.gameObject);
             if (hit.transform.tag == "Interactible")
             {
                 if (!hit.transform.GetChild(0).gameObject.activeInHierarchy)
                 {
                     return;
                 }
                 Interactible inter = hit.transform.GetComponent <Interactible>();
                 inter.Play(thisPlayer);
                 myPlayer = false;
                 Debug.Log("Played!");
             }
         }
     }
 }