using UnityEngine;
public class BarrelLauncher : Launcher {
private LaunchPoint[] launchPoints = new LaunchPoint[0];
private ParticleEmitter[] launcherEffects = new ParticleEmitter[0];
public float launchEffectsDuration = 3.0f;
private void ActivateLauncherEffect() {
foreach (ParticleEmitter emitter in launcherEffects) {
emitter.emit = true;
}
}
private void DeactivateLauncherEffect() {
foreach (ParticleEmitter emitter in launcherEffects) {
emitter.emit = false;
}
}
public void Launch() {
ActivateLauncherEffect();
foreach (LaunchPoint launchPoint in launchPoints) {
GameObject projectile = new GameObject("Projectile");
projectile.transform.position = launchPoint.transform.position;
projectile.transform.rotation = launchPoint.transform.rotation;
}
Invoke("DeactivateLauncherEffect", launchEffectsDuration);
}
void Awake() {
launcherEffects = GetComponentsInChildren<ParticleEmitter>();
}
}
Projectile.js
using UnityEngine;
using System.Collections;
public class Projectile : MonoBehaviour {
public float rateOfFire;
public GameObject primaryProjectile;
private float rateOfFireTimer = 0.0f;
void Update () {
//this is a counter that tells you the time in seconds from the last projectile fired
rateOfFireTimer += Time.deltaTime;
//this bit isn't necessary but I did it for debugging purposes
print (rateOfFireTimer);
//Fire Primary Weapon. I do (1/rateOfFire) so that you can enter a number like 10 in the inspector to mean 10 per second
// if (Input.GetButton ("Fire1") && rateOfFireTimer >= (1/rateOfFire))
// FirePrimaryWeapon();
}
void FirePrimaryWeapon() {
//this fires the projectile
Instantiate (primaryProjectile, transform.position, Quaternion.identity);
//this resets the timer
rateOfFireTimer = 0.0f;
}