I have a fairly simple script that spawns weapons at a choice of locations.
Currently it spawns a new weapon the exact moment the old one is collected. How do I go about putting a delay on that?
I thought a simple ‘yield WaitForSeconds()’ statement would do it, but you having no luck. I’ve tried adding the waitforseconds before/after almost every line in the script but it either has no effect at all, the weapon spawn goes wild or I get error messages about functions can’t be coroutines?
#pragma strict
var spawnPoint : Transform[]; // Create list of possible spawn locations
var wepType : GameObject[]; // Creat list of possible weapons to be spawned
var wepPresent : boolean = false;
function Start()
{
SpawnWeapons(); //Run SpawnWeapons coroutine
}
function Update()
{
if(wepPresent == false) //Check to see if weapon is present
{
SpawnWeapons(); //If no weapon is present run SpawnWeapons coroutine
}
}
function SpawnWeapons() //Spawns a random weapon at one of possible spawn locations
{
var randomLoc : int = Random.Range(0,spawnPoint.length); //Pick random number between the min and max values of the array containing the spawn locations.
var randomWep : int = Random.Range(0,wepType.length); //Pick random number between the min and max of the array containing the weapon types.
var newWeapon = Instantiate(wepType[randomWep], spawnPoint[randomLoc].position, spawnPoint[randomLoc].rotation);
newWeapon.GetComponent(DestroySelfOnContact).getSpawnHandler = this.gameObject;
//Pick random weapon depending on which number was generated by 'randomWep'
//Spawn weapon at location depending on which number was generated by 'randomLoc'
wepPresent = true;
if(newWeapon.GetComponent(DestroySelfOnContact).destroyed == true)
{
wepPresent = false;
}
}
Any suggestions please guys ???