Hello All,
I am up to the challenge at approx @15:00, and I have hit the wall regarding the spawning of enemy attackers.
At the moment all the lanes are only spawning the first member of the GameObjects array. For instance, in Lane 1, I made Lizzy first element and only that object spawns; and in Lane 2, I made FoxxyLoxxy the first element and that’s the only object that spawns and I can’t figure out why. The code does have a problem in that the first spawn is hardcoded rather than a variable, I wanted it that way though, I can sense that there is a problem in that only one timer is set instead of one for each object (maybe??), but, still can’t see through the fog.
And I don’t want the answer just hints. The code in Update, isTimeToSpawn and Spawn is as follows, as always please excuse the verbose comments it the way I script these days:
/// <summary>
/// Spawn (GameObject myGameObject)
/// </summary>
/// <param name="myGameObject"></param>
//spawn the object - easy peasy: clone=instantiate(object, possy,rotate)
public void Spawn(GameObject myGameObject)
{
GameObject clone = Instantiate(myGameObject, possy, Quaternion.identity) as GameObject;
print("myGameObject: " + myGameObject.name);
//set the clone to the parent object: Spawner_parent
clone.transform.parent = Spawner_parent.transform;
//This sets the timer 'x' seconds into the future again
Timer = Time.time + myGameObject.GetComponent<Attacker>().seenEverySeconds;
}
// Update is called once per frame
// need to do something here calling the Spawner with timer functions
// and whatnot to call whatever GameOject to be instantiated
void Update () {
//using foreach method to cycle through the AttackerPrefabs array
//foreach(Type, whatever name you choose, in ArrayName
foreach(GameObject baddie in AttackerPrefabs)
{
//do something
if(isTimeToSpawn (baddie) )
{
//do something
//spawn the attacker
Spawn(baddie);
}//end if
}//end foreach loop
}//end Update
bool isTimeToSpawn(GameObject attacker)
{
//print("Baddie: "+attacker.name);
//float getNumber;
//getNumber = attacker.GetComponent<Attacker>().seenEverySeconds;
//print("Get Number: "+getNumber);
if (Timer < Time.time)
{ //This checks wether real time has caught up to the timer
return true;
}
else
{
return false;
}
//return false;
}//end bool isTimeToSpawn;
If you are able to help me see the errors of my ways, just hints please, then here is a big thankyou in advance.
Regards,
Vaughan.