- Home /
Ammo GUI Help
I've looked into this but i'm not sure where to go from what I have here. I'm trying to have a simple HUD showing the remaining bullets of my gun, as I shoot it goes down and then goes back up to 8 when I reload. can anyone point me in the right direction with this please?
This is what I have so far...
var fullClip : int = 8;
var bulletsLeft : int = 8;
function OnGUI() { GUI.Label (Rect (10, 10, 100, 20), "8/99"); }
Answer by FLASHDENMARK · Jul 17, 2012 at 04:15 PM
Well, assuming that you are using you previous shoot script, then you should simply add that function to your script:
var muzzleFlash : GameObject;
var spawnPoint : Transform;
var fullClip : int = 8;
var bulletsLeft : int = 8;
function Update () {
if(Input.GetButtonDown("Fire1")){
if(bulletsLeft > 0 ){
bulletsLeft -- ;
Instantiate(muzzleFlash, spawnPoint.position, spawnPoint.rotation);
}
}
if(Input.GetButtonDown("r")){
bulletsLeft = fullClip ;
}
}
//This one!!!
function OnGUI() {
GUI.Label (Rect (10, 10, 100, 20), ""+bulletsLeft);
}
I don't understand, I know this isn't meant to work but I don't know where to go with this anyway can you help a bit more please?
I updated the post a little. Not sure if it helps. Can you explain what you are stuck with? If you haven't already you can check out the Scripting Reference for a little insight in the GUI system.
What i'm trying to do is have 1 number on my screen that says the number of shots I have left before i have to reload, like in most modern shooters.
How would I make the number go down when the L$$anonymous$$B has been clicked and then back up to 8 when r is pressed?
Your answer
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
XBox 360 controller for the GUI 1 Answer
Is there anyway to only show a part of a GUI image during the game? (C#) 1 Answer
gui help for ammo display 1 Answer
GUI font size? 1 Answer