Hey everyone I research a bunch of time on the waitforseconds method. It is not working at all. I looked and looked on the forms for answers and nothing seems to work. I want the game to pause before the game really starts, but the game seems to just go without anything happening.
Here is the Code:
using UnityEngine;
using System.Collections;
public class ballControl : MonoBehaviour {
public float ballSpeed = 100;
// Use this for initialization
void Start() {
StartCoroutine(Wait());
GoBall();
}
void GoBall()
{
float randomNumber = Random.Range(0, 2f); // needs to be 2
if (randomNumber <= 0.5)
{
rigidbody2D.AddForce(new Vector2(ballSpeed, 10));
Debug.Log("shoot Right");
}
else
{
rigidbody2D.AddForce(new Vector2(-ballSpeed, -10));
Debug.Log("shoot Left");
}
}
// called once per frame automactally
void OnCollisionEnter2D (Collision2D collInfo) {
if (collInfo.collider.tag == "Player")
{
Debug.Log("ITS WORKING!");
rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, rigidbody2D.velocity.y/2 + collInfo.collider.rigidbody2D.velocity.y/3 );
}
}
// This function waits 5 Seconds before starting the game
IEnumerator Wait()
{
print(Time.time);
yield return new WaitForSeconds(2);
}
}