Game Development Reference
In-Depth Information
public class RocketLauncher : MonoBehaviour {
public ParticleSystem smoke;
public ConstantForce rocket;
public float speed = 10f;
public int ammoCount = 20;
float lastShot = 0.0f;
RocketUI _rocketUI;
void Start () {
_rocketUI =
GameObject.FindObjectOfType<RocketUI>();
}
public void Fire( float reloadTime) {
if (Time.time > (reloadTime + lastShot) &&
ammoCount > 0) {
ConstantForce rocketPrefab = ConstantForce.
Instantiate(rocket, transform.position,
transform.rotation)as ConstantForce;
rocketPrefab.relativeForce = new Vector3(0, 0,
speed);
smoke.Play();
//We ignore the collision between rocket and
character
Physics.IgnoreCollision(rocketPrefab.collider,
transform.root.collider);
//Get the last shot time
lastShot = Time.time;
//Decrease the bullet
ammoCount--;
_rocketUI.UpdateUI(ammoCount);
}
}
Search WWH ::




Custom Search