In my splitscreen shooter instead of having to pick up weapons, each plaer has all the weaons at the start but so far all the guns have unlimited ammo, I am using an automatic rigidbody shooting script that is added to an empty prefab child in each weapon prefab called ‘firing point’, I want to change my shooting script to have a limited supply of held ammo. So basically when a weapon’s ammo has depleated I want it to disable the firing point child so the player cant shoot it anymore and then when the player comes into contact with an ammo pickup I want to tell the ammo pickup to send a message to the shooting script to add ammo to the weapon and re-enable the firing point child so the player can use the weapon again.
here’s my script
RequireComponent(AudioSource);
var audioSource: AudioSource;
var Projectile : Rigidbody;
var ProjectileSpeed : int = 10;
var FireRate : float = 10; // The number of bullets fired per second
var lastfired : float; // The value of Time.time at the last firing moment
var gunshot : AudioClip;
var muzzleflash :Transform;
function Start() {
audioSource = GetComponent.();
}
function Update ()
{
if (Input.GetAxis(“Fire1”)>0f)
{
if (Time.time - lastfired > 1 / FireRate)
{
lastfired = Time.time;
var clone : Rigidbody;
clone = Instantiate(Projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection (Vector3.forward * ProjectileSpeed);
audioSource.PlayOneShot(gunshot, 0.7F);
Instantiate (muzzleflash,transform.position,transform.rotation);
}
}
}