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 Grizzly · Aug 18, 2014 at 05:44 PM · javascriptraycast3dtext

How to make 3D texts show ammo?

Allright ,so I got my script for shooting ,and now I want when my ammo decrease in the script to make 3d text show that on screen in game mode ,I will have to make a few more variables for that but how do I conect those two to interact with each other.

I gues I will need two 3d texts , one for current ammount of bullets and one for number of clips.

This is not a GUI text so function OnGUI wont work here.

I need some hints ,its basicaly just to connect them to work together.

Comment
Add comment · Show 3
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 Grizzly · Aug 18, 2014 at 06:20 PM 0
Share

If you need more information from me ,if this question is not precise ,say it ,This is really important for me.

Please.

So far I tryed adding first variables into my shooting script:

 var ShowCurrentAmmo : Transform; 
 var ShowClipsLeft : Transform;

So I can insert the 3d text mesh into the script in inspector but other than that I am lost ...

avatar image KaliTech · Aug 18, 2014 at 06:21 PM 1
Share

I posted an answer about 20 $$anonymous$$utes ago, still waiting for approval.

avatar image Grizzly · Aug 18, 2014 at 06:28 PM 0
Share

Thanks $$anonymous$$ali ,I wonder why the answer is waiting for approval?

4 Replies

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

Answer by Amirmy · Aug 18, 2014 at 07:29 PM

You Should Use textmesh Not Transform

You can Do it like (C#):

 Public TextMesh ShowCurrentAmmo,ShowClipsLeft;
 
 void UpdateAmmo()
 {
      ShowCurrentAmmo.text = AmmoValue.ToString();
      ShowClipsLeft.text = ClipValue.ToString();
 }

Then call UpdateAmmo(); when the player shoots. or just put ShowCurrentAmmo.text = AmmoValue.ToString(); and ShowClipsLeft.text = ClipValue.ToString(); after the ammo decreases.

Also don't forget to Drag and drop your 3dtexts in ShowClipsLeft and ShowCurrentAmmo.

Javascript:

 var ShowCurrentAmmo: TextMesh;
 var ShowClipsLeft: TextMesh;
 
 
 ShowCurrentAmmo.text = AmmoValue.ToString();
 ShowClipsLeft.text = ClipValue.ToString();

ps: I would recommend to use Gui Text for better experience.

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 Grizzly · Aug 18, 2014 at 07:52 PM 0
Share

Thank you so much ,you are the best ,I would buy you a drink if you were close to where I live :D

avatar image Amirmy · Aug 20, 2014 at 09:26 AM 1
Share

@Grizzly , You're most welcome! I'm more than happy to help you out, cheers!

avatar image
1

Answer by KaliTech · Aug 18, 2014 at 07:29 PM

Hi,

You don't actually need two 3d texts, you could use one that, as an example will say 10/2, where the 10 is the amount of bullets, and 2 is the amount of clips you have.

What you need to do is take a TextMesh as a variable, and in your Update function you could just set the text with: yourTextMesh.text = bullets.ToString() + "/" + spareClips.ToString(); (Untested code)

Just change the variables accordingly.

Best of luck,

KaliTech.

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

Answer by DESTRUKTORR · Aug 18, 2014 at 06:30 PM

You should only need one 3D text. You will just need to use two variables to set its text value.

  1. Create a 3D Text object (either by adding the TextMesh and TextRenderer components to a GameObject, or via the GameObject/Create menu command)

  2. Get a reference to the TextMesh component for your 3D text, in the script that handles the shooting.

  3. Convert the two variables into strings, and set TextMesh.text to the string concatenated between the two, assuming you want just a slash between them.

If you want to do something else, then you may want to have two separate TextMesh objects, yes. However, managing two references would be extremely similar to managing one reference, just you would need to set the "text" attribute separately for both objects, and to the appropriate values.

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 Grizzly · Aug 18, 2014 at 06:41 PM 0
Share

First of all ,thank you very much for this information I cant find anything about this on google ,but the thing is I never worked with this before so I dont really know how to pull this off ,can you explain more please ,like how the code lines should look ,or if you need ,I might even add my script here ,I doubt it needs lot of lines to make it work.Sorry if I sound like jerk now ...

avatar image DESTRUKTORR · Aug 22, 2014 at 01:42 PM 0
Share

If you need to ask how the syntax looks, you may want to consider looking more into how to program in C# (or just about any C-based language, for that matter) than how to program for Unity.

avatar image
1

Answer by $$anonymous$$ · Aug 18, 2014 at 07:26 PM

In C#, it would be like this.

 TextMesh.text = AmmoLeft.ToString() + " / " + AmmoLeftInClip.ToString ();


Im not very good in Javascript, so you may end up having to change a few things in this code in order to get it to work. In C#, this should work.

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

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

25 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Trouble with raycasting 0 Answers

My timer script makes Unity crash... 0 Answers

Gun Script Help 2 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