• 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 /
  • Help Room /
avatar image
0
Question by hjd22 · Oct 08, 2015 at 12:20 AM · cs

How to make ammo appear on screen in c sharp

Hi, I am working on a game with my friend and I have made a shoot script and it works fine, it uses ammo and the ammo part works i just dont know how to make the ammo count appear on screen. I have looked for tutorials, but i only found them in javascript. I was hoping to figure out how to do this in c#. If you know of any good videos or websites that could help me do this or you know how to do this please show me, thank you. Also this is the first time i have posted a question sorry if i did it wrong

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by OctoMan · Oct 08, 2015 at 01:13 PM

When you use Unity 4.6 and the Canvas system, create a textfield where ever you want the count.
In your script add the namespace:

 using UnityEngine.UI;

So you have access to textfields and stuff Now you create a connection to that Textfield.

 public Text AmmoAmount;

Now drag the textfield in Slot in your inspector.
Finally write data into that textfield whenever you use a shot or relaod.

 AmmoAmount.text = yourAmmoValue.toString();

Thats it. Cheers

Comment
Add comment · Show 2 · 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 hjd22 · Oct 08, 2015 at 04:05 PM 0
Share

Will this work in unity 5.1.1?

avatar image hjd22 · Oct 08, 2015 at 09:41 PM 0
Share

Thank you so much, I have been trying to get this to work for the past week, lots of thanks.

avatar image
0

Answer by etopsirhc · Oct 08, 2015 at 01:17 AM

add a label ui element, then in the script add a public variable of that type and drag it into the slot in the inspector. after that you just need to set variableName.text to the number you want to display.

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 hjd22 · Oct 08, 2015 at 12:45 PM 0
Share

But is the number i add constantly changing because thats what the ammo would be doing?

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How save data file using System.IO ? 1 Answer

Weird Script behaviour 1 Answer

Enable or disable a gameobject with a buttonpress 0 Answers

Get a Insantiate particle system follow a GameObject 1 Answer

Problemas con Input.GetKeyDown() 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges