Guest User

Untitled

a guest
Feb 16th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. IEnumerator DrawLineToMouse(float range)
  2. {
  3.  
  4. RayCastHit hit;
  5. Vector3 endPos;
  6. float rangeSquared = Mathf.Sqrt(range);
  7.  
  8. while (Input.GetButton("Fire1"))
  9. {
  10.  
  11. if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 2000))
  12. {
  13.  
  14. endPos = (hit.point - startPos).normalized * rangeSquared; // startPos is the starting point of the line to be drawn
  15.  
  16. Debug.DrawLine(startPos, hit.point, Color.green, Time.deltaTime);
  17. Debug.DrawLine(startPos, endPos, Color.red, Time.deltaTime);
  18.  
  19. }
  20.  
  21. yield return null;
  22. }
  23.  
  24. }
  25.  
  26. endPos = startPos + (hit.point - startPos).normalized * rangeSquared;
Add Comment
Please, Sign In to add comment