Advertisement
Guest User

Untitled

a guest
Oct 14th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. // Based on the script found here: http://weeklycoder.com/2015/08/13/make-a-circle-using-linerenderer-in-unity/
  2.  
  3. public static void CreateCircle(this LineRenderer line, int segments, float radius)
  4. {
  5.     line.CreateCircle(segments, radius, radius);
  6. }
  7.  
  8. public static void CreateCircle(this LineRenderer line, int segments, float xRadius, float yRadius)
  9. {
  10.     line.SetVertexCount(segments + 1);
  11.     line.useWorldSpace = false;
  12.  
  13.     float x;
  14.     float y;
  15.     float z = 0f;
  16.  
  17.     float angle = 20f;
  18.  
  19.     for (int i = 0; i < segments + 1; i++)
  20.     {
  21.         x = Mathf.Sin(Mathf.Deg2Rad * angle) * xRadius;
  22.         y = Mathf.Cos(Mathf.Deg2Rad * angle) * yRadius;
  23.  
  24.         line.SetPosition( i, new Vector3(x,y,z) );
  25.  
  26.         angle += 360f / segments;
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement