I have health bar textures and a working health system but how do i make it into a bar? so how would i change between the images according to how much health is left out of 100??
asked May 13, 2010 at 01:31 PM
I know this has been answered a ton of times, but I thought I'd answer it :)
My way of doing this:
SliderVar being the slider type variable.
PlayerVar being the public GameObject you wrote in the health script, PlayerScript being the player's script, and HealthVar being the health variable in the player's script.
Hope this helps :-)
Here is a way to set this up for the player's health in case anyone is looking for that solution in the future (in C#).
This will work perfectly if you have a script attached to your main character (in this example PlayerMoveScript) with two public static variables for the player's current health (playerHealth), and their maximum health (playerHealthTotal). Just make sure that their maximum health is a float or the division will not work properly.
You can create two textures in Photoshop and size them to be identical to the Vector 2 (size) variable. Once you import the textures into Unity (.PSD extension works fine) you can switch the texture type from Texture to GUI in the Inspector.
Hope this helps someone!