Classic Fireball Shooting Up Obstacle

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());
	}

}
  1. You check “projectile” before deciding whether to instantiate or not. I assume you want to create a new one when the first one is destroyed?
  2. You add force to the projectile every frame (in the update). Instead just set the velocity to the starting velocity you want, but only once when instantiating, not every frame.
  3. You need to add code to projectile that will destroy it after it finishes falling or the new one won’t be created ever.
  4. Make sure your projectile is affected by gravity.