Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IEnumerator DrawLineToMouse(float range)
- {
- RayCastHit hit;
- Vector3 endPos;
- float rangeSquared = Mathf.Sqrt(range);
- while (Input.GetButton("Fire1"))
- {
- if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 2000))
- {
- endPos = (hit.point - startPos).normalized * rangeSquared; // startPos is the starting point of the line to be drawn
- Debug.DrawLine(startPos, hit.point, Color.green, Time.deltaTime);
- Debug.DrawLine(startPos, endPos, Color.red, Time.deltaTime);
- }
- yield return null;
- }
- }
- endPos = startPos + (hit.point - startPos).normalized * rangeSquared;
Add Comment
Please, Sign In to add comment