#UI bullets Issue

1 messages Β· Page 1 of 1 (latest)

agile marten
#

Good idea

#

you have two loops. right?

#

Okay, and what error do you get with what loop?

real perch
#

yea thats a 12 right there

agile marten
#

Okay, so, show your loop again with that removeat thing

#

bullets are gameobjects?

#

okay

#

So you want to update on every shot what value? MaxCap is just for the max magazine, right? So where do you have your current mag capacity

#
foreach(Image bltImg in bullets)
  bltImg.enabled = bullets.IndexOf(bltImg) > bulletsInMag;
#

Can you try that

#

Yes

#

You might wanna convert it to a for loop to not ask for indexof all the time, but with 12, it is not really necessary

#

Oh I think you gotta use < bulletsInMag, not > πŸ˜„

real perch
#

my brain hurts

agile marten
#

Try asking your question, cause this is none πŸ˜„

sharp rune
#

uhh... if you don't know how to do reverse for, you can use regular for, but with an if that bullet in the index is suppouse to activate

#

Welll... you have to trigger the request the recoloring everytime the user shoots the button

agile marten
#

Shooting should just affect bulletsInMag

agile marten
#

You gotta fire your foreach loop on every change of bulletsInMag

#

Is that the UpdateBulletUI?

#

But it does not make sense. If you shoot, you gotta run the foreach again to enable the correct amount of images

#

Wait what? πŸ˜„ where is that in code

sharp rune
#

why is the recoloring happen only when the user switch weapons ?

agile marten
#

Okay, lets refactor this. You have two separate lists of bullets?

#

One for blue of max cap and one for red bullets being shot?

#

Okay

#

Okay, and on weapon switch you update the images to be blue and put the amount of max magazine in

real perch
#

wouldnt it be easier if theres a red background color

agile marten
#

Okay, is the amount of bullets working for now with the foreach?

#

Okay, we can simplify that with the foreach loop and your colouring too

#

Woops, hit enter accidentally

#

no wait, bulletsInMag should be maxBullets in the foreach,r ight?

#

because bulletsInMag is the current available bullets, not the max

#
foreach(Image bltImg in bullets)
{
  bltImg.enabled = bullets.IndexOf(bltImg) < bulletsMagCap;
  bltImg.color = bullets.IndexOf(bltImg) < bulletsInMag ? Color.blue : Color.red;
}
#

you could get the index upfront to store in an int or use a for i loop too, just my quick discord approach here

#

What is your MagCap and InMag, they should be both the same value, right?

#

I am only disabling when the index is higher or equal magCap

#

nope

#

bulletsInMag and MagCap

#

the function should work without any parameter. You shoot, update your bulletcount, call updateUI

#

remove the whole for loop below our foreach

#

the second line in the foreach loop is all doing this

#

What happens if you shoot

#

You still got the same value in the foreach loop....

#

bulletsmagcap!!

#

in the enabled = ... line

#

bltImg.enabled = bullets.IndexOf(bltImg) < bulletsMagCap; not < bulletsInMag

#

yes? πŸ˜„

#

Your keyboard? πŸ˜‰

#

Cool πŸ™‚

#

You know start is only being called ONCE on runtime on your script

#

I get why some people advise you to do basic tutorials again πŸ˜‰ no offence, but this isbasic stuff.
Awake is just being called on every script before Start is being called on every script. That is called exeuction order.

#

You want it to be called on every weapon change, dont you

#

Cause every weapon has different mag sizes?

#

but bulletsInMag is changing on shooting

#

Can you please show your entire script with hastebin or pastebin or what not

#

Yeah, not the best thing to start learning c# and unity. Do a little flappy birds game first. Then go over and maybe a shooter single person level and so on

#

Seriously, I am basically writing the code for you and you dont know what Start() does. But feeling offended when someone tells you the facts?

#

I am sure someone else will help you with the final bit. I am tired of people feeling offended because they THINK they are more experienced that they are. Accept the critic and think about it or not. I dont mind.

real perch
#

still at ammo

#

why that

#

comon dont be like that

#

what dat new

#

in which script is that

#

why

#

well when i dont know how to fix smt i just take a break

#

ye man gn

#

yes but only zombies

#

origins

#

and de

#

wind

#

srongest

#

strongest

#

with unity??

#

isnt there a extra tool to make custom maps in bo3

#

how long would it take to create the sprites just for that

#

oh yea

#

yes

#

ye

#

i just woke up tho

#

live in germany

#

8 am

#

damn

#

u made that

#

i just do 2d but that looks good tho

#

just 4 months

#

u

#

?

#

ok u made weapons too?

#

line raygun mark 2

#

like*

#

just know about bo3 weapons

#

not that one

#

ok well imma head out gn