- Home /
GUI Bullet bar help
i have the GUI bullet bar script but how can i make them go down each 5 Bullets? it looks like this: |||||||||||||||||||||||||||||||||||||||||||||
but i want it like this:
|||||||||||||||||||||||
||||||||||||||||||||||
how can i make this?
for (var i : int = 1; i <= BulletsLeft; i++){
GUI.DrawTexture(Rect(10 + ((i - 1) * (BulletTexture.width + 2)), 10, BulletTexture.width, BulletTexture.height), BulletTexture);
}
Answer by Chronos-L · Apr 01, 2013 at 01:39 AM
for (var i : int = 0; i < BulletsLeft; i++){
GUI.DrawTexture(
Rect(
10 + ( i * (BulletTexture.width + 2)),
10 + ( i/10 * (BulletTexture.height + 2)),
BulletTexture.width,
BulletTexture.height
), BulletTexture
);
}
Second parameter for the Rect is for the y position, just offset the position every n
bullet, in example, n
= 10, so you will get 10 bullets per row.
I also re-adjust the var i. var i : int = 1
is not wrong, but var i : int = 0
makes the offset calculation easier (you don't have to always use ( i - 1 )
to get the correct offset )
yeah i tried it, now it goes down every 10 rows, but its not going back to the first x position :/
Oh, my bad. Forgot to test the script. This should work, by using modulus % and division /.
for (var i : int = 0; i < BulletsLeft; i++){
GUI.DrawTexture(
Rect(
10 + ( (i%10) * (BulletTexture.width + 2)),
10 + ( (i/10) * (BulletTexture.height + 2)),
BulletTexture.width,
BulletTexture.height
), BulletTexture
);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613095438im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Ammo GUI Help 2 Answers
Gun Ammo HUD? 1 Answer
Cameras Switch Based On Button Click 1 Answer
Render Sprite on Screen at 3d game 0 Answers