I am trying to make a “fireball” (in this case water) spawn every 3 seconds, shoot straight up, and fall back down. Like the classic fireball obstacle in old Mario games.
With the code I have so far, it just sends the waterball straight up and it never comes back down. Also, another one does not spawn after 3 seconds. Coding is not my thing so if anyone could help that would be great.
using UnityEngine;
using System.Collections;
public class waterBall : MonoBehaviour {
public float shotDelay = 3f;
public Projectile projectile;
private float shotHeight = 20;
// Use this for initialization
void Start () {
if (shotDelay > 0) {
StartCoroutine(OnFire());
}
}
// Update is called once per frame
void Update () {
if (projectile) {
Projectile clone = Instantiate(projectile,transform.position, Quaternion.identity) as Projectile;
}
GetComponent<Rigidbody2D>().AddForce(new Vector2(0, shotHeight));
}
IEnumerator OnFire(){
yield return new WaitForSeconds(shotDelay);
StartCoroutine(OnFire());
}
}