SHARE
TWEET

Untitled

a guest Oct 15th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CameraDebugLog : MonoBehaviour
  6. {
  7.     void Update()
  8.     {
  9.         if (Input.GetMouseButtonDown(0))
  10.         {
  11.             RaycastHit2D hit;
  12.             if(hit = Physics2D.Raycast(new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y), Vector2.zero, 0.0f))
  13.             {
  14.                 HandleRay(hit);
  15.             }
  16.         }
  17.     }
  18.  
  19.  
  20.     void HandleRay(RaycastHit2D hit)
  21.     {
  22.         Debug.Log("Raycast hit: " + hit.collider.name + " (X, Y, Z): " + hit.collider.transform.position);
  23.  
  24.         Interactable interactable = hit.transform.GetComponent<Interactable>();
  25.  
  26.         if (interactable != null)
  27.             interactable.BeenHit();
  28.     }
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top