Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by samaxi · Jul 06, 2013 at 01:37 PM · javascriptfpsammofpstutorial

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;
 }
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gamerant · Jul 07, 2013 at 09:08 PM 0
Share

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.

avatar image cdrandin · Jul 07, 2013 at 09:11 PM 0
Share

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.

avatar image tw1st3d · Jul 07, 2013 at 09:59 PM 0
Share

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.

avatar image samaxi · Jul 08, 2013 at 06:15 PM 0
Share

I followed cdrandin's advice, and wrote it my way and got it to work, Thanks everyone.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

ammo display javascript 1 Answer

How do you make a enemy AI hear approaching footsteps? 2 Answers

How do I make an enemy lead his shots? 2 Answers

BCE0044 expecting ), found 'script' and BCE0043 unexpected token ) 2 Answers

2 in 1 question - Enemy transforms and Frames per second 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges