AI doesn't do damage

Hello, I was making a multiplayer fps and tried to add AI
now, my AI doesn’t do damage to the player(s)
I only get this debug error: ‘Sendmessage hp has no receiver!’
this is the code from the error: target.SendMessage( "hp", Random.Range(minDamage, maxDamage)); hp is the public variable of the player health and this is the target: var target : Transform; `
I did assigned this with NetworkingPlayer (is it to do with the change of the object name to the player name cause it’s multplayer?)

This is probably a very stupid mistake, but I can’t fix it

2 Answers

2

For SendMessage, you need a method name not variable name. You add this method to your player script

public function PlayerHealth( health: float)
{
         hp = health;
}

Then call SendMessage( “PlayerHealth”, Random.Range(minDamage, maxDamage );

thanks, my playerdamage script is in cs what is the alternative for that?

Here you go public void PlayerHealth( float health) { hp = health; }

thanks ;p it works fine now

Can you accept this answer as it would help others who have same question.

how do you mean?

how do you mean?

Click the circle below the thumbs on Sundars answer. It marks the question solved with an accepted answer, gives poor Sundar some Karma points and makes you feel good.

http://video.unity3d.com/video/7720450/tutorials-using-unity-answers 7 minutes 40 minutes in, will show you how :P

can not vote if i have not 15 reputation...