Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement