ok so the problem is the gun fires 7 times does the reload animation but when i try shoot the sound of the firing/the bullets dont come out of the gun but the firing animation shows i have tried a bit but cant fix it so im asking if anyone can help i’ll make a video if that would help more
so basicly the gun doesnt reload with bullets and the shooting sounds stop
english not first language sorry is bad
var Bullet : Rigidbody;
var Spawn : Transform;
var BulletSpeed : float = 1000;
var ReloadTime : float = 2;
var AmmoInMag : float = 7;
static var AmmoLeft : float;
static var ReloadTTime : float;
static var IsReloading = false;
private var CanFire = true;
function Start () {
AmmoLeft = AmmoInMag;
ReloadTTime = ReloadTime;
}
function Update () {
if(Input.GetButtonDown("Fire1")){
if(AmmoLeft > 0){
BroadcastMessage("FireAnim");
Fire();
}
}
if(AmmoLeft == 0)
{
Reload();
}
if(AmmoLeft < 0){
AmmoLeft = 0;
}
}
function Fire(){
if(CanFire == true IsReloading == false){
var bullet1 : Rigidbody = Instantiate(Bullet,Spawn.position,Spawn.rotation);
bullet1.AddForce(transform.forward *BulletSpeed);
AmmoLeft -= 1;
audio.Play();
}
}
function Reload(){
CanFire = false;
IsReloading = true;
BroadcastMessage("ReloadAnim");
isReloading = false;
CanFire = true;
AmmoLeft = AmmoInMag;
}
It will play the fire animation because ammoLeft > 0 at this point, so the condition is checked as true, therefore processing the FireAnim argument. It will not, however, play the sound or shoot the bullet, because in the Fire() function, IsReloading is stuck on True.