This question was
closed Dec 31, 2015 at 12:13 PM by
$$anonymous$$.
Question by
$$anonymous$$ · Dec 31, 2015 at 01:35 PM ·
c#2d gameyield
How to make program wait for 2 seconds?
Hello, guys, I've been trying to make a Pong game, so I've just tried to make some "pause" for 2 seconds(to get player ready). So here's my script:
void Start()
{
myRigidBody2D = GetComponent<Rigidbody2D>();
NewGame();
}
void NewGame()
{
int randomNumber = Random.Range(0, 2);
yield return new WaitForSeconds(2f);
if (randomNumber <= 0.5)
{
myRigidBody2D.AddForce(new Vector2(80f, Random.Range(5f, 100f)));
}
else
{
myRigidBody2D.AddForce(new Vector2(-80f, -Random.Range(5f, 100f)));
}
}
I know that in problems like this, we should use WaitForSeconds(float sec) , but how should I use it in practice?
Comment
Follow this Question
Related Questions
Dialogue script shows previous sentences after a while 0 Answers
Starting an Animation from an Instantiated Object 0 Answers
add yield to an already existing project 0 Answers
Upgrading the OnLevelWasLoded code to sceneloaded in Gamemanager Script for 2D Rougelike game 0 Answers
2D movement along vector 1 Answer