Advertisement
Guest User

Untitled

a guest
Jun 11th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. void DrawLazer()
  2. {
  3. Vector2 origin = new Vector2(firePoint.transform.position.x, firePoint.transform.position.y);
  4.  
  5. Vector2 direction = transform.TransformDirection(Vector2.up);
  6.  
  7. RaycastHit2D hit = Physics2D.Raycast(origin, direction, 10f);
  8. Debug.DrawLine(origin, direction *10000, Color.black);
  9. if (hit)
  10. {
  11. Debug.Log("Hit: " + hit.collider.name);
  12. var whatWeHit = new Vector2(hit.transform.position.x, hit.transform.position.y);
  13. var offset = whatWeHit + hit.point;
  14. offset.y = 0;
  15.  
  16. RaycastHit2D hit2 = Physics2D.Raycast(offset, Vector3.Reflect(direction, hit.normal) * -10000);
  17.  
  18. if (hit2)
  19. {
  20. Debug.DrawLine(offset, -Vector3.Reflect(direction, hit.normal) * -10000);
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement