#Health Bar not going down when colliding with object

1 messages · Page 1 of 1 (latest)

austere gust
#

hi there!!
I followed the video on how to create a healthbar, the only thing i changed was instead of pressing the spacebar key to take damage, i made it such that when the player collides with the danger object, the player takes damage. However, the OnCollisionEnter function cannot be placed in the update function, so right now i have no idea how to pass that information into the update
(I'm actually not sure if im doing this right because my basics in unity is a little wonky)

I also set a debug log to check that the player has collided with the danger object and it shows, so the problem definitely does not lie with the collision part i think

steel ivy
#

I am not so sure but i think you should do SetHealth() instead of set maxhealth in theTakeDamage function. Because your health is lowering, but with it the max health, so it looks like your health bar isnt moving and you arent taking any damage.

#

The OnCollisionEnter function doesnt have to be in the update function to be checked

#

it gets checked automatically whenever the player collides with sth

#

i hope this helps in some way

austere gust
austere gust
#

at first i thought it was because the slider was not linked in the healthbar, but it is linked, and the code looks exactly the same too, so im not exactly sure why it doesnt change

steel ivy
#

so 80 health becomes 100% of the health

#

and after it 60, 40, 20

austere gust
#

ohh

steel ivy
#

you can fix it by writing healthbar.sethealth()

#

@austere gust did you fix it? thonk

austere gust
#

im encountering a few errors haha

#

give me a few tries

steel ivy
#

ok

#

lemme know if it works

austere gust
steel ivy
#

did you spell healthbar the right way?

#

dont copy what i wrote 1 by 1

#

try to write it in there and look at what visual studio is giving you as a tip

#

it you like the tip, press tab

#

and it will fill it in

#

you def spelled it wrong

#

cuz I am very sure this does exist in this context PepoSmug ThinkConfused

austere gust
#

HAHAHA uhh im so sorry i think im just bad at this but now it tells me There is no argument given that corresponds to the required parameter 'health' of 'HealthBar.SetHealth(int)'

#

i changed the spelling too

#

but also, by doing this, do i have to add in something to my public? if that makes sense

#

ITS OK NOW IT WORKSSSSSS

steel ivy
austere gust
#

Thank you veryveryveryvery muchh