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.
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.
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)
You should only need one 3D text. You will just need to use two variables to set its text value.
Create a 3D Text object (either by adding the TextMesh and TextRenderer components to a GameObject, or via the GameObject/Create menu command)
Get a reference to the TextMesh component for your 3D text, in the script that handles the shooting.
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.