Hello, im a noob trying to code a method that generates points equally distanced from each other contained in a Box Collider
. The code below spawns all the points in a single position a not even in the Box Collider
.
Thanks for the help
public class Grid : MonoBehaviour
{
public BoxCollider navArea;
public GameObject navPointPrefab;
[SerializeField] int numberOfPoints = 5;
int spaceBtwPoints;
private void OnValidate()
{
GenerateNavigationPoints();
}
private void GenerateNavigationPoints()
{
int origineX = (int)(navArea.center.x - navArea.size.x / 2);
int origineZ = (int)(navArea.center.z - navArea.size.z / 2);
spaceBtwPoints = (int)(navArea.size.x / numberOfPoints);
if (navArea != null && navPointPrefab != null)
{
for (int i = 0; i < numberOfPoints; i++)
{
for(int j = 0; j < numberOfPoints; j++)
{
Vector3 position = new(origineX, 0 ,origineZ);
Instantiate(navPointPrefab, position, Quaternion.identity);
origineX =+ spaceBtwPoints;
}
origineZ =+ spaceBtwPoints;
}
}
}
}