Skip to content

Instantly share code, notes, and snippets.

@smkplus
Last active January 15, 2019 13:11
Show Gist options
  • Save smkplus/e469c02e391df7ef52adf78fb2b0b06f to your computer and use it in GitHub Desktop.
Save smkplus/e469c02e391df7ef52adf78fb2b0b06f to your computer and use it in GitHub Desktop.
Unity SemiCircle

https://gamedev.stackexchange.com/questions/128432/how-to-draw-an-arc-between-two-angles

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[ExecuteInEditMode]
public class Point : MonoBehaviour {
public float startAngle,endAngle;
public int segments;
public float radius;

public List<Vector2> arcPoints = new List<Vector2>();
private void Update() {
	arcPoints.Clear();
float angle = startAngle;
float arcLength = endAngle - startAngle;
	for (int i = 0; i <= segments; i++)
{
    float x = Mathf.Sin(Mathf.Deg2Rad * angle) * radius;
    float y = Mathf.Cos(Mathf.Deg2Rad * angle) * radius;
	
    arcPoints.Add(new Vector2(x,y));

    angle += (arcLength / segments);
}
	for (int j = 0; j < segments; j++)
{
	Debug.DrawLine(arcPoints[j],arcPoints[j+1],Color.red);
}

}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment