I want to disable the OnGUI() function, when the gameobject is not a Player. Since it stores the stats in this script and is used globally for damagecalculation, I don’t want to do two different scripts.
So my question is, how could this be done?
if(isHuman){
function OnGUI(){
//show lifebar
}
}
this doesn’t work.
But does this?
if(isHuman)
OnGUI();
function OnGUI(){
//show lifebar
}
If statements needs to be inside of functions. You can not use them to exclude one of unitys event functions from running. You can use them inside of the function to exclude the content from running.
Easiest would be:
function OnGUI()
{
if(isHuman)
{
//show lifebar
}
}