daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest Feb 16th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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;
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