I have a TakeDamage script and a Player script.
In my TakeDamage script, I have function to test how to recive damage by pressing the down button and I alsp tried with an object. That worked fine.
But in my player script I have all the animations setup.
How can i refere to the currentHealth which is in my TakeDamage script, into my PLayer script?
I want when currentHelath is zero then i play a dead animation…
This isn’t a great programming practice, but for the small and simple games I’ve been making I just use a global script with public variables for things like player health. These can be accessed from any other script.
In many cases the best way to handle this is with Unity events. Your TakeDamage script should have some public event on it like “onDeath” which it calls when the health goes <= 0. And your Player script should have a public method on it like “Die”. Then, in the inspector for your player game object, you can connect the onDeath event up to the Die method.
This blog post/video on Unity Events may help make all that clear.
1 Like