I have a mob spawner script that has a timer int for how often an object spawns, variable for the prefab that I want to get spanwed and ints for how far and close the player must be for the script to disable.
But I would want to have multiple variable spots for diffrent objects and also having another variable for what % chance it has to be spawned. Any help for where to start from?
My current mob spawner scrpt:
var enemy: GameObject;
var spawnTime:float = 3f;
var player : Transform;
var CloseDistance = 3; //Close Enough
var CloseEnough : boolean = false;
var FarDistance = 12; //Far Enough
var FarEnough : boolean = false;
var isInInvoke : boolean = true;
private var thisTransform : Transform;
function Start(){
thisTransform = transform;
player = GameObject.FindWithTag("Player").transform;
}
InvokeRepeating ("Spawn", this.spawnTime, this.spawnTime);
function Spawn (){
Instantiate (enemy, thisTransform.position, thisTransform.rotation);
}
function Update(){
//Close Enough
if(Vector2.Distance(transform.position, player.position) < CloseDistance){
CloseEnough = true;
} else {
CloseEnough = false;
}
if (CloseEnough == true) {
CancelInvoke("Spawn");
isInInvoke=false;
}
if (CloseEnough == false && isInInvoke==false) {
InvokeRepeating ("Spawn", this.spawnTime, this.spawnTime);
isInInvoke=true;
}
//Far Enough and Close Enough
if(Vector2.Distance(transform.position, player.position) > FarDistance){
FarEnough = true;
} else {
FarEnough = false;
}
if (FarEnough == true) {
CancelInvoke("Spawn");
isInInvoke=false;
}
if (CloseEnough == false && isInInvoke==false) {
InvokeRepeating ("Spawn", this.spawnTime, this.spawnTime);
isInInvoke=true;
}
}