In this script I'm creating a circle with specific radius size and get the radius size :
using UnityEngine; using System.Collections; [RequireComponent(typeof(LineRenderer))] public class DrawRadiusAroundTurret : MonoBehaviour { [Range(0, 50)] public int segments = 50; [Range(0, 5)] public float xradius = 5; [Range(0, 5)] public float yradius = 5; [Range(0.1f, 5f)] public float width = 0.1f; LineRenderer line; void Start() { line = gameObject.GetComponent<LineRenderer>(); line.enabled = true; line.positionCount = segments + 1; line.widthMultiplier = width; line.useWorldSpace = false; CreatePoints(); } private void Update() { CreatePoints(); } public Vector3[] CreatePoints() { line.widthMultiplier = width; float x; float y; float z; float angle = 20f; 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, 0f, y)); angle += (380f / segments); } var positions = new Vector3[line.positionCount]; return positions; } } And in this script I have this method and I want the last point/s to be set randomly on the radius edge positions :
private void GeneratePointsInTracks() { var startPoints = GameObject.FindGameObjectsWithTag("Start Point"); var curvedLines = GameObject.FindGameObjectsWithTag("Curved Line"); for (int i = 0; i < startPoints.Length; i++) { for (int x = 0; x < numberOfPointsInTrack; x++) { GameObject go = Instantiate(tracksPrefab, curvedLines[i].transform); go.name = "Point In Track"; go.transform.position = turrent.position + new Vector3(Random.Range(-100f, 100f), Random.Range(-100f, 100f), Random.Range(-100f, 100f)); if(x == numberOfPointsInTrack - 1) { go.name = "Last Point In Track"; for(int y = 0; y < drawRadius.CreatePoints().Length; y++) { go.transform.position = new Vector3(Random.Range(0,1)[y].x, drawRadius.CreatePoints()[y].y, drawRadius.CreatePoints()[y].z); } } } } } I tried this :
go.transform.position = new Vector3(Random.Range(0,1)[y].x, drawRadius.CreatePoints()[y].y, drawRadius.CreatePoints()[y].z); but the random on the x give error :
Cannot apply indexing with [] to an expression of type 'int'
The first script create a circle like this :
And this is an example I drawed in paint just to show what I mean that I said I want the endPoints in the second script to be position randomly on the circle edges :
So each "Last Point In Track" object should be position randomly on the circle edge like in the second screenshot.


Random.Range(0,1)is just a number, not a collection, don't try to access it with an indexyvar positions = new Vector3[line.positionCount]; return positions;so you always return an array with zero vectors, which is not what you want