https://www.youtube.com/watch?v=vfl2HyEar68&list=PLu2uAkIZ4shpPdCTIjEpvhD8U-RRM3Y2F&index=3 regarding to this video how can i add rotation to these random placed objects???
Here is all the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GenerateGrid : MonoBehaviour
{
public GameObject blockGameObject;
public GameObject ObjectToSpawn;
private int worldSizeX = 10;
private int worldSizeZ = 10;
private int gridOffset = 5;
private List<Vector3> blockPositions = new List<Vector3>();
// Start is called before the first frame update
void Start()
{
for (int x = 0; x < worldSizeX; x++)
{
for (int z = 0; z < worldSizeZ; z++)
{
Vector3 pos = new Vector3(x * gridOffset, 0, z * gridOffset);
GameObject block = Instantiate(blockGameObject, pos, Quaternion.identity) as GameObject;
blockPositions.Add(block.transform.position);
block.transform.SetParent(this.transform);
}
}
SpawnObject();
}
private void SpawnObject()
{
for (int c = 0; c < 20; c++)
{
GameObject toPlaceObject = Instantiate(ObjectToSpawn, ObjectSpawnLocation(), Quaternion.identity);
}
}
private Vector3 ObjectSpawnLocation()
{
int rndIndex = Random.Range(0, blockPositions.Count);
Vector3 newPos = new Vector3(
blockPositions[rndIndex].x,
blockPositions[rndIndex].y +2.5f,
blockPositions[rndIndex].z
);
blockPositions.RemoveAt(rndIndex);
return newPos;
}
}