Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.42 KB | None | 0 0
  1.  private Enemy GetEnemy()
  2.     {
  3.         if (Input.GetMouseButtonDown(0))
  4.         {
  5.             var ray = Camera.main.ScreenPointToRay(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 1));
  6.  
  7.             var hit = Physics2D.Raycast(ray.origin, ray.direction);
  8.  
  9.             if (hit)
  10.             {
  11.                 return hit.collider.GetComponent<Enemy>();
  12.             }
  13.         }
  14.         return null;
  15.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement