Hello,
I have a problem and i think is t not very hard but i can’t fix it. Now i can shoot rockets but there is no limit, i can shoot unlimited and that not really realistic
thanks in advance,
Sander
Script:
using UnityEngine;
using System.Collections;
public class RocketSpawnSource : MonoBehaviour {
public GameObject RocketPrefab;
public static bool rocketShooted;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
{
Instantiate(RocketPrefab,transform.position,transform.rotation);
StartCoroutine("RocketShooted");
}
}
}
using UnityEngine;
using System.Collections;
public class RocketSpawnSource : MonoBehaviour {
public GameObject RocketPrefab;
public static bool rocketShooted;
public int RocketCoolDown = 5; // Used to assign in editor and reset the rocketCoolDownCount.
private int rocketCoolDownCount;
// Use this for initialization
void Start () {
rocketCoolDownCount = RocketCoolDown; // initialize the Cool down count.
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
{
if (rocketCoolDownCount > 0)
{
rocketCoolDownCount--;
}
else
{
Instantiate(RocketPrefab,transform.position,transform.rotation);
StartCoroutine("RocketShooted");
}
}
}
}
In your RocketShooted method that you didn’t include here, you need to reset the rocketCoolDownCount to RocketCoolDown.
// in your RocketShooted method, after shooting
rocketCoolDownCount = RocketCoolDown;