So I made this script used the rocket launcher example from the fps tutorial, and i wanted to add a muzzle flash. Im trying to take the concept from the machine gun’s muzzle flash and some how adding it into the launcher’s one, but it just doesn’t seem to work.
Heres my updated script:
var launchPos : Vector3;
var projectile : Rigidbody;
var initialSpeed = 20.0;
var reloadTime = 0.5;
private var lastShot = -10.0;
var muzzleFlash : Renderer;
var reloadRealTime = 5;
var bulletsPerClip = 100;
static var bulletsLeft : int = 100;
static var clipsLeft : int = 2;
var isReloading : boolean = false;
var fireRate = 0.05;
private var nextFireTime = 0.0;
function LateUpdate() {
if(Input.GetButtonDown("Reload") clipsLeft >= 1 isReloading == false)
Reload();
}
function Fire () {
if (bulletsLeft == 0 clipsLeft >=1 isReloading == false) {
Reload();
return;
}
// Did the time exceed the reload time?
if (Time.time > reloadTime + lastShot bulletsLeft > 0)
{
//Fix the launch position of the rocket
var launchPos : Vector3 = transform.TransformDirection(new Vector3(0.5, 0, 3));
// create a new projectile, use the same position and rotation as the Launcher.
var instantiatedProjectile : Rigidbody = Instantiate (projectile,transform.position + launchPos, transform.rotation);
// Give it an initial forward velocity. The direction is along the z-axis of
// the rocket launcher's transform.
instantiatedProjectile.velocity = transform.TransformDirection(Vector3(0, 0, initialSpeed));
// Ignore collisions between the rocket and the character controller
Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
lastShot = Time.time;
FireOneShot();
}
}
function FireOneShot () {
//decrease bullets by 1.
bulletsLeft--;
//gun reload in time
if (bulletsLeft == 0 clipsLeft >=1 isReloading == false) {
Reload();
}
}
function Reload (){
if (!isReloading)
{
isReloading = true;
SendMessageUpwards("setEnableWeaponSwitch", false);
//audio.PlayOneShot(reloadSound, 1.0 / audio.volume);
// Wait for reload time first - then add more bullets!
yield WaitForSeconds(reloadRealTime);
// We have a clip left reload
if (clipsLeft > 0 ) {
clipsLeft--;
bulletsLeft = bulletsPerClip;
}
SendMessageUpwards("setEnableWeaponSwitch", true);
}
isReloading = false;
}
static function GetBulletsLeft () {
return bulletsLeft;
}
static function GetClipsLeft () {
return clipsLeft;
}
Any ideas? Thanks in advance.