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 Novaspire · Apr 15, 2012 at 02:52 PM · guifpstutorialammo

ammo count help

I am currently using the first person shooter tutorial, and though i know its pretty out of date thats irrelevant to my problem. On the GUI it shows the current ammo count of my first weapon. Ive added in a heavy rifle right now, and the ammo for that is showing. However im trying to get it to change to my regular rifle when that is equipped. My current code isnt changing the two. The code I have is as follows:

private var machineGun : MachineGun; private var rocketLauncher : RocketLauncher; private var heavyMachineGun : HeavyMachineGun;

function Awake () { machineGun = GetComponentInChildren(MachineGun); rocketLauncher = GetComponentInChildren(RocketLauncher); heavyMachineGun = GetComponentInChildren(HeavyMachineGun); }

if (machineGun) { bulletGUI.text = machineGun.GetRegularBulletsLeft().ToString(); } if (heavyMachineGun) { bulletGUI.text = heavyMachineGun.GetHeavyBulletsLeft().ToString(); }

Comment
Add comment · Show 1
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 fafase · Apr 15, 2012 at 04:17 PM 0
Share

When you post codes, highlight the code sectio and press ctrl+k or the 101010 button. that makes it easier to read and you are more likely to get help.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Piflik · Apr 15, 2012 at 04:34 PM

Does your script compile? The reason I ask is that MachineGun, RocketLauncher and HeavyMachineGun are not valid variable types.

You would have to declare the variables like this:

 private var machineGun : Transform = null;
 private var rocketLauncher : Transform = null;
 private var heavyMachineGun : Transform = null;
 
 function Awake() { 
     machineGun = GetComponentInChildren(MachineGun); 
     rocketLauncher = GetComponentInChildren(RocketLauncher); 
     heavyMachineGun = GetComponentInChildren(HeavyMachineGun); 
 }

 function Update() {
     if(machineGun != null)
         bulletGUI.text = machineGun.GetRegularBulletsLeft().ToString();
     if(heavyMachineGun != null)
         bulletGUI.text = heavyMachineGun.GetHeavyBulletsLeft().ToString();
 }   
Comment
Add comment · Show 1 · Share
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 Novaspire · Apr 18, 2012 at 01:48 PM 0
Share

the script did compile before, I tried the variable declaration like above and I got the error: "Cannot convert '$$anonymous$$achineGun' to 'UnityEngine.Transform'" etc for the rest.

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

6 People are following this question.

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

Related Questions

Game Object enable for game mode selection on GUI 1 Answer

Making a Tutorial in th emiddle of screen and more efficiant 1 Answer

GUI Resolution Ajust 1 Answer

Question about fliping a character 1 Answer

How to Make a FPS without knowledge [BEGINNER] ! 5 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