- Home /
Why is this Pickup Script Not Updating my GUI for ammo
I've made some changes to the FPS tutorial's Pickup script only I can't figure out why it's not updating my GUI text. My Health bar works great, I pick up a health box and it adds to my health bar so that one is fine.
My Rockets were working but now they're not.
My Ammo for my Shotgun is working but I can't seem to get it to apply an ammo pickup when I run over the ammo box I set up.
And my grenade pickup I've never been able to get to work!!
And my Machine gun was working before too by for some reason it's not any more. Man this stuff drives me buggy! Here is my Pickup Script. If you need to see my individual weapon's scripts let me know and I'll re- edit this with those scripts.
enum PickupType { Health = 0, Rocket = 1, Ammo = 20, Shells = 10, Grenades = 20 } var pickupType = PickupType.Health; var amount = 20; var sound : AudioClip;
private var used = false;
function ApplyPickup (player : FPSPlayer) { if (pickupType == PickupType.Health) { if (player.hitPoints >= player.maximumHitPoints) return false;
player.hitPoints += amount;
player.hitPoints = Mathf.Min(player.hitPoints, player.maximumHitPoints);
}
else if (pickupType == PickupType.Rocket) {
var launcher : RocketLauncher = player.GetComponentInChildren(RocketLauncher);
if (launcher)
launcher.ammoCount += amount;
}
else if (pickupType == PickupType.Ammo) {
var ammo : MachineGun = player.GetComponentInChildren(MachineGun);
if (ammo)
ammo.bulletsPerClip += amount;
}
else if (pickupType == PickupType.Shells) {
var Shells : Shotgun = player.GetComponentInChildren(Shotgun);
if (Shells)
Shells.bulletsPerClip += amount;
}
else if (pickupType == PickupType.Grenades) {
var Grenades : MissileLauncher = player.GetComponentInChildren(MissileLauncher);
if (Grenades)
Grenades.ammoCount += amount;
}
return true;
}
function OnTriggerEnter (col : Collider) { var player : FPSPlayer = col.GetComponent(FPSPlayer);
//* Make sure we are running into a player
//* prevent picking up the trigger twice, because destruction
// might be delayed until the animation has finnished
if (used || player == null)
return;
if (!ApplyPickup (player))
return;
used = true;
// Play sound
if (sound)
AudioSource.PlayClipAtPoint(sound, transform.position);
// If there is an animation attached.
// Play it.
if (animation && animation.clip) {
animation.Play();
Destroy(gameObject, animation.clip.length);
} else {
Destroy(gameObject);
}
}
// Auto setup the pickup function Reset () { if (collider == null)
gameObject.AddComponent(BoxCollider); collider.isTrigger = true; }
You havn't actually asked a question you have just listed things that don't work with your game. Try debug logging it, try saving severzl versions of the project and keeping a developer diary so you know what you have changed and when things broke. Also if you don't ask a question how the hell are you going to get an answer?
Well I don't know anything about the stuff yur talking about in that first part, I'm just not that technical $$anonymous$$ded, 2nd my codeing knowledge is not that great. So I thought I was giving as much information about my problems as I can, I even mentioned that if more information was required I'd place it in an update.
Your answer
Follow this Question
Related Questions
GUI player menu is not updating values (score, exp, HPs) 1 Answer
Script variables resetting on play 0 Answers
GUI text like GTA 2 Answers
GUI Final Scene/ Item Pickup 0 Answers
GUI dependent on an int variable 1 Answer