The Random
class in Unity3D provides the method insideUnitCircle
that returns a random Vector2 inside a circle with radius = 1. By calling normalized
, the Vector length (or magnitude) will be increased to 1. That effectively puts the random point on the edge of the circle.
The RandomPointOnCircleEdge
function returns the random point as a Vector3 where y=0.
private Vector3 RandomPointOnCircleEdge(float radius) { var vector2 = Random.insideUnitCircle.normalized * radius; return new Vector3(vector2.x, 0, vector2.y); }