- Home /
 
Script not working at ALL
I am using the FPS Tutorial package and it's working really well but there is one problem, the package has a health and rocket pickup but I need to change the rocket to ammo for the machinegun. This code doesn't work. I can comment the original rocket code if that would help, I am very desperate to get this code working.
 enum PickupType { Health = 0, Ammo = 1 }
 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.Ammo) {
         var MachineGun : MachineGun = player.GetComponentInChildren(MachineGun);
         if (MachineGun)
             MachineGun.clips += 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;
 }
 
              I would say the original code would help everyone else a lot as it's hard to see where the changes have been made to the original code.
It is just me but beginner wise I would suggest making an entirely new script so you understand how it is working ins$$anonymous$$d of using someone else code and modifying it because it has a lot of moving parts and tampering can highly break it. So, when making your own script use the FPS package as a guide and see what you need and modify to your needs. Best practice tip imo.
In each of your if statements, add a debug line like, "Debug error 1", so you can see how far your code gets. It will help you immensely.
I followed cdrandin's advice, and wrote it my way and got it to work, Thanks everyone.
Your answer