- Home /
Question by
dichterDichter · Feb 22, 2017 at 09:16 AM ·
updatelinerendererresetarc
reset Line Renderer every second
im drawing an arc which shows me the rotation a gameobject will do. so for example im drawing it from 45° to 135°. Thats working with from/to at start. i would like to update this rotation while im rotating so for example redrawing the arc.
or is there a better way for drawing an arc around a gameobject and update it ? I tried to set the numPositions to 0 but it doesnt work.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CircleDrawer : MonoBehaviour
{
public int segments;
public float xradius;
public float yradius;
LineRenderer line;
void Start()
{
line = gameObject.GetComponent<LineRenderer>();
line.numPositions = segments + 1;
line.useWorldSpace = false;
}
public void ResetLines() {
line.numPositions = 0;
}
public void CreatePoints(int from, int to)
{
line.numPositions = segments + 1;
float x;
float y;
float z = 0f;
float angle = 20f;
int amount = to - from;
transform.localRotation = Quaternion.Euler(90, 160 + from, 0);
for (int i = 0; i < (segments + 1); i++)
{
x = Mathf.Sin(Mathf.Deg2Rad * angle) * xradius;
y = Mathf.Cos(Mathf.Deg2Rad * angle) * yradius;
line.SetPosition(i, new Vector3(x, y, z));
angle += (amount / segments);
}
}
}
Comment