It looks like you're new here. If you want to get involved, click one of these buttons!
i have a hp float assigned to my player but i dont know how an enemy could access it and decrease it, the trigger for decreasing health is the one used in ep 10 of brackeys rpg tutorial.
if (distance <= agent.stoppingDistance)
{
FaceTarget();
Attack();
}
the attack funtion would need to access my players hp varaiable and decrease it, but not sure how.
Answers
Hey!!
First you need to declare playerhealth script as a variable in your enemy script like
public MyPlayerHealth MPH; (public your scriptname and a variable)
Then in your start function write this
MPH(variable of that script) = gameObject.GetComponent<MyPlayerHealth>();
here MyPlayerHealth is the name of yourScript
And if you want to call a meathod from it write
MPH(variablename).DoSomething();(function name)
Hope it helps!!!!!!!!!!!!!!
thanks, ill try it out