I've done this get component stuff 1000 times and its worked just fine, but its been a while so I don't remember if this is right. I would like it to work without making a public variable for the player but that wasn't working either. I am trying to access the player's script NPCDropper when the health equals Zero. and set the boolean to true.
public class EnemyHealth : MonoBehaviour {
public int curHP;
public int maxHP;
public GameObject player;
void Start ()
{
curHP = maxHP;
}
void Update ()
{
if(curHP <= 0)
{
var npcD = player.GetComponent();
npcD.weShouldDrop = true;
}
}
}
↧