- Home /
Question by
Rohan Negi · Jun 21, 2015 at 10:55 AM ·
2dinstantiatespawnspawninginvoke
How to spawn 2 events with a score gap..?
I've want to run two spawning events after a gap of 50 in score..till 50 first event spawn after that next event start and first one stops..But it works only till the score of 200..not after that..Can you find the problem or give a easy approach how to achieve this ?
void FixedUpdate()
{
if (player.spawnCon == 1)
{
if ((player.score - prevScore) > 50)
{
prevScore = player.score;
temp++;
if (temp == 1)
{
c = 1;
}
else if (temp == 2)
{
c = 2;
temp = 0;
}
}
}
if ((horizontal == 1) && ((c == 1) && (a == 0)))
{ //JUMPING
a = 1;
b = 0;
Invoke ("Spawn", Random.Range (2, 5));
}
if ((c == 2) && (b == 0))
{//DOWNWARDS
b = 1;
a = 0;
Invoke ("Spawn", Random.Range (2, 5));
}
}
}
}
void Spawn()
{
if (player.spawnCon == 1 && isCloud == 0)
{
if ((horizontal == 0) && ((player.score < 50) || (c==2)))
{ //DOWNWARDS
Instantiate (obj [Random.Range (0, obj.GetLength (0))], transform.position, Quaternion.identity);
Invoke ("Spawn", Random.Range (spawnMin, spawnMax));
}
else if ((horizontal == 1) && (c == 1))
{ //LEFT TO RIGHT
Instantiate (obj [Random.Range (0, obj.GetLength (0))], transform.position, Quaternion.identity);
Invoke ("Spawn", Random.Range (spawnMin, spawnMax));
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How to make objects appear with mouse click in a row? 2 Answers
Spawning prefabs dependant upon Health UI? 2 Answers
Object Spawning Randomly 0 Answers
What's wrong with my script? 1 Answer