Hey guys I’m having and issue with my pick scripts. I have sit a “ammo limit” and set my pick up item to send a message to add an amount of ammo to the gun. Lets say my gun shoots 199 out of 200 ammo, then when I pick up my ammo it adds more then the 200 max. Like if I was at 199 it makes it 209 and then adds no more if I pick up more ammo. Here are my scripts.
the pick up box “pick up”
#pragma strict
var ammoPickUp = 10;
function OnCollisionEnter (col : Collision) {
col.gameObject.BroadcastMessage(“ammoPickedUp”, ammoPickUp, SendMessageOptions.DontRequireReceiver);
Destroy(gameObject);
}
An this is the Gun it self script
#pragma strict
// shoot obj machineGun
var projectile : Transform;
var bulletSpeed : float = 20;
var damage = 10;
static var ammoMG = 200;
function Update () {
// Put this in your update function
if (Input.GetButtonDown(“MGfire”)&& ammoMG > 0) {
// Instantiate the projectile at the position and rotation of this transform
var clone : Transform;
clone = Instantiate(projectile, transform.position, transform.rotation);
// Add force to the cloned object in the object's forward direction
clone.rigidbody.AddForce(clone.transform.forward * bulletSpeed);
}
if (Input.GetButtonDown("MGfire")&& ammoMG >0) {
ammoMG -= 1;
}
}
function ammoPickedUp (ammoPickUp : int) {
if (ammoMG <= 200){
ammoMG += ammoPickUp;
}
}
function OnCollisionEnter (col : Collision) {
col.gameObject.BroadcastMessage(“ApplyDamage”, damage, SendMessageOptions.DontRequireReceiver);
}
function OnGUI () {
GUI.Label (Rect (20, 20, 100, 20),“MGammo:” + ammoMG );
}
Now I just can’t see why the pick up massage over rides my max ammo count? Basically from what I can understand I’m send a “plus 10 message” and it adds 10, but its adding more then the maximum of 200. I so lost on how to make it that the ammo will only take what it needs to be 200 and no more.