Advertisement
Xyberviri

DrawCircle.cs

May 10th, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class DrawCircle : MonoBehaviour
  6. {
  7.     float theta_scale = 0.01f;        //Set lower to add more points
  8.     int size; //Total number of points in circle
  9.     [SerializeField]
  10.     float radius = 13f;
  11.     [SerializeField]
  12.     LineRenderer lineRenderer;
  13.    
  14.     void Awake()
  15.     {
  16.         float sizeValue = (2.0f * Mathf.PI) / theta_scale;
  17.         size = (int)sizeValue;
  18.         size++;
  19.         //lineRenderer = gameObject.AddComponent<LineRenderer>();
  20.         //lineRenderer.material = new Material(Shader.Find("Particles/Additive"));
  21.         lineRenderer = gameObject.GetComponent<LineRenderer>();
  22.         lineRenderer.startWidth = 0.1f;
  23.         lineRenderer.endWidth = 0.1f;
  24.         lineRenderer.positionCount = size;
  25.     }
  26.  
  27.     void Update()
  28.     {
  29.         Vector3 pos;
  30.         float theta = 0f;
  31.         for (int i = 0; i < size; i++)
  32.         {
  33.             theta += (2.0f * Mathf.PI * theta_scale);
  34.             float x = radius * Mathf.Cos(theta);
  35.             float z = radius * Mathf.Sin(theta);
  36.             x += gameObject.transform.position.x;
  37.             z += gameObject.transform.position.z;
  38.             pos = new Vector3(x, gameObject.transform.position.y, z);
  39.             lineRenderer.SetPosition(i, pos);
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement