using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BallSpawner : MonoBehaviour
{
public Transform spawn1;
public Transform spawn2;
public Transform spawn3;
public GameObject ball;
private int num;
private float ballSpeed = 500f;
IEnumerator Spawn()
{
while (true)
{
yield return new WaitForSeconds(3);
num = Random.Range(0, 4);
num = (int) num;
yield return new WaitForSeconds(0.001f);
num = 0;
}
}
void Start()
{
StartCoroutine(Spawn());
}
void Update()
{
CheckNum();
}
void CheckNum()
{
if (num == 1)
{
Instantiate(ball, spawn1.position, Quaternion.identity);
ball.GetComponent<Rigidbody>().AddForce(new Vector3(1f, 1f, 1f) * ballSpeed);
}
if (num == 2)
{
Instantiate(ball, spawn2.position, Quaternion.identity);
ball.GetComponent<Rigidbody>().AddForce(new Vector3(1f, 1f, 1f) * ballSpeed);
}
if (num == 3)
{
Instantiate(ball, spawn3.position, Quaternion.identity);
ball.GetComponent<Rigidbody>().AddForce(new Vector3(1f, 1f, 1f) * ballSpeed);
}
}
}
num = Random.Range(0, 4);
num = (int) num;
yield return new WaitForSeconds(0.001f);
num = 0;