- Home /
Can anyone help check for colliders in this spawning script so that the spawns don't overlap each other or spawn inside of walls, objetcs etc
This is the script and when it's instantiating I need it to check for its surroundings of other colliders I'm guessing so that no prebabs are overlapping or get instantiated into a wall if the spawn area goes through a wall or object. Thanks if you can
public class MonsterSpawnArea : SpawnArea { public float interval; public float intervalBreakables; public MonsterEntity[] monsterPrefab; [Range(0, 100)] public int amount;
public GameObject[] breakables;
[Range(0, 100)]
public int breakablesamount;
private bool SpawnComplete = false;
private bool BreakablesComplete = false;
public void Update()
{
if (interval > 0)
{
interval -= Time.deltaTime;
}
else
{
if(SpawnComplete == false)
{
SpawnMonsters();
SpawnComplete = true;
}
}
if (intervalBreakables > 0)
{
intervalBreakables -= Time.deltaTime;
}
else
{
if(BreakablesComplete == false)
{
SpawnBreakables();
BreakablesComplete = true;
}
}
}
public void SpawnMonsters()
{
if (interval <= 0)
{
for (int i = 0; i < amount; ++i)
{
PhotonNetwork.InstantiateSceneObject(monsterPrefab[Random.Range(0, monsterPrefab.Length)].name, GetSpawnPosition(), Quaternion.identity, 0, new object[0]);
}
}
}
public void SpawnBreakables()
{
if (interval <= 0)
{
for (int i = 0; i < breakablesamount; ++i)
{
PhotonNetwork.InstantiateSceneObject(breakables[Random.Range(0, breakables.Length)].name, GetSpawnPosition(), Quaternion.identity, 0, new object[0]);
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
instanstiate Spawns more then one objec 0 Answers
How to spawn 2 events with a score gap..? 0 Answers
Random.onUnitSphere Hemisphere? 2 Answers
Object Spawning Randomly 0 Answers
What's wrong with my script? 1 Answer