C# How to have a scripted if statement last x amount of seconds
So we are making a game, and we have this code
if (collider.gameObject.name == "GravPill")
Physics2D.gravity = new Vector3 (0,-0.5F,0);
rb.velocity = new Vector3(0,-10,0);
StartCoroutine (ExecuteAfterTime(10));
The Coroutine is this:
IEnumerator ExecuteAfterTime(float time){
yield return new WaitForSeconds(time);
Physics2D.gravity = new Vector3 (0,10F,0);
}
Basically, we want our ball to lose gravity (Done) and revert back to the original after x seconds once a pill has been eaten (we have the pill set up, everything works except the effect (gravity being changed) lasting x seconds. it just carries on, infinitely through scenes.
I understand the code below is of poor quality, but we are learning, and for now we are happy the majority works. Thank you in advance
Answer by SeuDigao · Aug 11, 2017 at 05:17 PM
Try this:
IEnumerator ExecuteAfterTime(float time){
Physics2D.gravity = new Vector3 (0,-0.5F,0);
yield return new WaitForSeconds(time);
Physics2D.gravity = new Vector3 (0,10F,0);
}
Your answer
Follow this Question
Related Questions
I need my timer to only start after it hits a trigger. Please help! 0 Answers
Load scene after time 1 Answer
How to make an App that only works for a week? 1 Answer
Clock doesn't stop when reaches 0.0. Can you help me with this. 1 Answer
How is it possible to verify values and is they are correct activate objects ? 0 Answers