My code which will be below is one that I wrote from scratch and from what I can tell it should be working, but it doesn’t because of the following error which don’t fix no matter what I try. The purpose of the audio code is probably unimportant because it is just the error I want to fix but I’ll tell you. I’m making a spawning script and at the start I want it to say that there are 30 seconds left until the spawning will take place and then another audio clip when the monsters begin to spawn to tell the player that the monsters are spawning. I have tried the below method and i tried the exact same thing with audio.PlayOneShot(audioclip)( without the audio.clip = audioclip before it) but that didnt work either and it had some other error about no audio source, but i would appreciate it if someone can tell me how i can fix the audio problem because i couldn’t find a solution to this error online.
var unitToSpawn: GameObject;
var spawnPoint: Transform;
var wayPoint: Transform;
var waveNumber: int = 1.0;
var numberOfUnitsOnField: int = 0;
var thirtySecondsUntilSpawn = AudioClip;
var monstersHaveSpawned = AudioClip;
function Start(){
//Play this so that the player knows to be ready
audio.clip = thirtySecondsUntilSpawn;
audio.Play();
//The initial 30 seconds of wait time before the monsters spawn
yield WaitForSeconds(30);
audio.clip = monstersHaveSpawned;
audio.Play();
//Spawn the first wave.:
if (numberOfUnitsOnField ==0){
var numberOfUnitToSpawn: int = ((waveNumber * 2)+ 5);
while (numberOfUnitToSpawn > 0){
//spawn one monster every 0.5 seconds until wave is complete
yield WaitForSeconds(0.5);
var instance:GameObject = Instantiate(unitToSpawn, spawnPoint.position, spawnPoint.rotation);
numberOfUnitToSpawn = numberOfUnitToSpawn -1;
//not sure if a rigidbody is necessary for lerp to work or not
instance.AddComponent("Rigidbody");
instance.position = Vector3.Lerp((spawnPoint.position),(wayPoint.position), 5 * Time.deltaTime);
}
waveNumber +=1;
}
}
thanks in advance for any help and i will make sure that i will reply and select the correct answer asap. =]