Here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rayManager : MonoBehaviour {
[Tooltip("Diameter.")]
[Range(0.125f, 5)]
public float holeSize;
public int resolution;
public GameObject model;
[Range(5f, 15f)]
public float modelDistance;
public Vector3 modelRotation = new Vector3();
public Vector3 modelSize = new Vector2();
private float height;
private float width;
private List<Vector3> spawnLocation = new List<Vector3>();
private Vector3 cubeScale = new Vector3();
private Vector3 cubePosition = new Vector3();
private List<Vector3> point = new List<Vector3>();
public GameObject cubeTop;
public GameObject cubeBottom;
void Awake()
{
model = Instantiate(model, new Vector3(-modelDistance, 0f), Quaternion.Euler(modelRotation));
model.transform.localScale = modelSize;
if (resolution <= 2)
resolution = 2;
if (holeSize <= 0.125)
holeSize = 0.125f;
cubeTop = Instantiate(cubeTop);
cubeBottom = Instantiate(cubeBottom);
CalculateSpawnPoints();
}
void Update()
{
Transform modelTransform = model.transform;
modelTransform.localPosition = new Vector3(-modelDistance, 0f);
modelTransform.localRotation = Quaternion.Euler(modelRotation);
modelTransform.localScale = modelSize;
height = Camera.main.orthographicSize * 2;
width = height * Screen.width / Screen.height;
cubeScale = new Vector3(width * 0.005f, (height - holeSize) / 2, 1);
cubePosition = new Vector3(0, height / 4 + holeSize / 4);
cubeTop.transform.localScale = cubeScale;
cubeTop.transform.localPosition = cubePosition;
cubeBottom.transform.localScale = cubeScale;
cubeBottom.transform.localPosition = -cubePosition;
cubeBottom.transform.name = "Bottom Cube";
cubeTop.transform.name = "Top Cube";
if (resolution <= 2)
resolution = 2;
}
public void CalculateSpawnPoints()
{
spawnLocation.Clear();
float spawn = 0f;
for (spawn = -holeSize; spawn <= holeSize; spawn += holeSize * 2 / resolution)
{
spawnLocation.Add(new Vector3(0f, spawn));
Debug.Log(spawn);
}
Debug.Log(spawnLocation[0]);
Debug.Log(spawnLocation[resolution]);
}
}
Nothing here is really as important as the list, but I gave the whole script in case it helps. So the script will have its Count as big as resolution+1. I don’t want to access every Vector3 in the list manualy, but instead I want to make it so that somehow I can make the code access it itself. The vectors are just spawn points. If you want to you can put the script in a project and just fill everything out and it should work. Also if I was hard to understand or something is unclear please ask in the comments its late here so I might make no sense.