Skip to content

Instantly share code, notes, and snippets.

@SenpaiRar
Created May 10, 2019 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SenpaiRar/96f3a32169ce21e46bd6743e569f5d6a to your computer and use it in GitHub Desktop.
Save SenpaiRar/96f3a32169ce21e46bd6743e569f5d6a to your computer and use it in GitHub Desktop.
This is the manager of the populators we have on our Game Manager empty gameobject.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Populator_Manager : MonoBehaviour
{
//IMPORTANT: Dynamic means objects that can be interacted with (Zombies, Crates, etc.) Static means objects that can't be interacted with like grass or trees
//Here we have the four populators we created. We create a reference to each one so we can easily access them.
public Zombie_Populator this_Zombie_Populator;
public Environment_Populator this_Environment_Populator;
public Crate_Populator this_Crate_Populator;
public Detail_Populator this_Detail_Populator;
//This number determines how some of the populator works
public int DifficultyLevel;
void Start(){
PopulateWorld();
DifficultyLevel = 1;
}
//This function goes through every populator and calls the function responsible for placing their respective gameobjects.
//Notice how in the Zombie and Enviornment Populator, we feed in their GetSpawnVectors() and SpawnVectors() repsectively, which
//satisfies the need for a random list of positions for those populators
public void PopulateWorld(){
this_Zombie_Populator.PopulateWorld(this_Zombie_Populator.GetSpawnVectors());
this_Environment_Populator.Populate_World(this_Environment_Populator.SpawnVectors());
this_Crate_Populator.Crate_Populate();
this_Detail_Populator.Spawn_Objects();
}
//Destroys all dynamic objects and respawns them.
public void ResetDynamicObjects(){
this_Zombie_Populator.DestroyAllSpawnedObjects();
this_Crate_Populator.DestroyAllObjects();
this_Zombie_Populator.PopulateWorld(this_Zombie_Populator.GetSpawnVectors());
this_Crate_Populator.Crate_Populate();
}
public void ResetWorld(){
this_Zombie_Populator.DestroyAllSpawnedObjects();
this_Crate_Populator.DestroyAllObjects();
this_Environment_Populator.DestroyGameObjectsSpawned();
this_Detail_Populator.Destroy_Objects();
this_Environment_Populator.Populate_World(this_Environment_Populator.SpawnVectors());
this_Zombie_Populator.PopulateWorld(this_Zombie_Populator.GetSpawnVectors());
this_Crate_Populator.Crate_Populate();
this_Detail_Populator.Spawn_Objects();
}
public void DestroyWorld(){
this_Zombie_Populator.DestroyAllSpawnedObjects();
this_Crate_Populator.DestroyAllObjects();
this_Environment_Populator.DestroyGameObjectsSpawned();
this_Detail_Populator.Destroy_Objects();
}
public void ChangeDifficultyLevel(int NewLevel){
//Prevents Modifiying the populator stats if the same difficulty level
if(DifficultyLevel != NewLevel){
DifficultyLevel = NewLevel;
this_Zombie_Populator.PackNumber *= DifficultyLevel;
this_Crate_Populator.CratesToSpawn *= DifficultyLevel;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment