- Home /
How i can make a function call and then after 15 sec another function call during this function call the first one stops.And this process keep repeating again and again.
I have a 2D game. I am in a problem. My game has three levels. Actually i have to cars. one is white other is yellow. And there are two types of incoming circles white and yellow. and currently my game is running perfectly. In level one, when yellow car collides with yellow it increases score.same for white car when it collide with white circle score increases. In level 2 everything is same except the factor that cars have to collect opposite color circles. Now in level 3 what i want is that when it starts the cars have to collect same color circles like in level one and after 15 sec cars have to collect opposite color circles like in level 2. and after 15 sec again cars have to collect same color circles like level one.. And this all keeps repeating. really need help its urgent guys. Thank you in advance. This code is for level 1
void OnTriggerEnter2D(Collider2D other){
if (other.CompareTag ("white") && car == "white") {
Destroy (other.gameObject);
SoundManager.instance.PlaySingle (circle);
count = count + 1;
SetCountText ();
}
if (other.CompareTag ("Yellow") && car == "white") {
Application.LoadLevel (2);
}
if (other.CompareTag ("Yellow") && car == "yellow") {
Destroy (other.gameObject);
SoundManager.instance.PlaySingle (circle);
count = count + 1;
SetCountText ();
}
if (other.CompareTag ("white") && car == "yellow") {
Application.LoadLevel (2);
}
}
This is for Level 2
void OnTriggerEnter2D(Collider2D other){
if (other.CompareTag ("Yellow") && car == "white") {
Destroy (other.gameObject);
SoundManager.instance.PlaySingle (circle);
count = count + 1;
SetCountText ();
}
if (other.CompareTag ("white") && car == "white") {
Application.LoadLevel (2);
}
if (other.CompareTag ("white") && car == "yellow") {
Destroy (other.gameObject);
SoundManager.instance.PlaySingle (circle);
count = count + 1;
SetCountText ();
}
if (other.CompareTag ("Yellow") && car == "yellow") {
Application.LoadLevel (2);
}
}
Answer by AlasdairHendry · Aug 11, 2017 at 03:45 PM
Private bool isOpposite = false;
Private float counter = 15.0f;
Private void Update ()
{
counter -= Time.deltaTime;
If(counter <= 0)
{
counter = 0;
isOpposite = !isOpposite;
}
If(isOpposite)
// Do the opposite colours
Else
// Do the normal colours
}
can you please elaborate this a bit. actually i'm a newbie. if you can explain it a little more then it will be very helpful for me. thank you in advance @AlasdairHendry
Your answer
Follow this Question
Related Questions
Call function after other objects have run their Start() function 2 Answers
Best practise time-based, repeating function calls: InvokeRepeating vs CustomSolution 0 Answers
Call a function repeatedly while a boolean is true 3 Answers
How to use yield within a class function 2 Answers
Recursive Function 0 Answers