I have a GUIhealthBar system, how do you script a pickup/health potion object that will modify this accordingly?
there isn't much documentation on this can anyone help?
I have a GUIhealthBar system, how do you script a pickup/health potion object that will modify this accordingly?
there isn't much documentation on this can anyone help?
Not to sound rude, but their's plenty of documentation...
Um, I guess I'd say, look at Broadcast Message: http://unity3d.com/support/documentation/ScriptReference/GameObject.BroadcastMessage.html
Now, put this in a simple Java script...
Psuedo Code: If player comes within 1 foot of the item, if the item is a HP, heal health, if item is AP, then heal armore...
Or, you can have the item in an "inventory" with a GUI object showing how much of it you have, so then:
if player clicks the potion button, add __ much to the HP, (Using broadcast message)...
See if that helps, also, their are a LOT of tutorials out there... Youtube is filled with them, you just have to look...
Good luck man!
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "healthpickup")
{
Destroy(hit.gameObject); // Destroys Health Box
print("Gained 10 Health")
VariableScript.health += 10;
}
}
Simple collider script. What this does is when you walk into a "medkit etc" you will gain 10hp.
It is a lot more complex if you want the whole Inventory thing with potions and using them. You could probably find one of the free inventorys by searching on the forum and then getting it to work with you game and then incorporate the health addition when the potion is used to suit your game.
Add this to the Player and tag the health pickup with "healthpickup" then have a script with all of your static vars such as health. (Which I have named VariableScript in this Code)
Untested code.
Thats picking up the health.
The rest depends on your gui and how it works.