HEY GUYS! Heres another *free* script to learn from! . Since I see a lot of posts about "wanting a script to do this or that" I'm giving them to you for free! This one is pretty simple all you need to do is attach the script to your player object. Set up the variables and you got yourself a health bar generated from 2d textures! Web Player: https://dl.dropbox.com/u/6629353/HealthBar.html -Source is attached-, Music NOT included! Let me know if you like it! Be sure to check out these threads: Advanced Inventory Equipment System Simple Inventory - Free Simple Health Bar - Free
, Lol really?! That part is up to you ^.^, Depending on how youre game is set up. Create a function that checks your health. have it get checked every time the player is hit. ex: function DeathCheck(){ if(health<=0){ //do some stuff that makes the player die. show an animation. move him to the beginning of the level. or whatever. } }
if(health<=0){ Debug.Log("you are dead...but you still can run, because you forgot to add a bloody DIEDIEDIE animation...or a huge explosion... like a super nova...hey...you are still reading..the game is over, dude - YOU LOOOOOOSE!!! "); }
Please release more source code for free. I don't care what. You're notation makes it easy to follow and learn from for us artist who are not so great with programming.
Hello, My question is , can I use this to follow my units by floating over their head ? Like the healthbar in RTS games. If so, how can I do it ? Thanks
No . Youll need to use GUI and check if enemy is in view and if so track the enemy from the screen point and display it over his head. but in the screen. Or use a physical object that is parented to the enemy and update that objects renderer (Image on material) with proper image. and so on.
For a reason i get an error when i apply the scripts on my Player! i get to see the gui in the center but not the health bar! The error is IndexOutOfRangeException: Array index is out of range.
Hey there, This is super old so I have no idea if this still works or not.. But I think the error may be caused from.. One of the scripts has an array on it, after applying it to a gameobject you need to apply texture2ds to some variables.. Should be an array for images of the bar and different values. Ex: 10%, 20%, 30%, 100% etc. element 0 is probably 0%, and the last element would be 100%