[SOLVED!]
I am trying to reset player’s health back to 100 when he dies.
this is the health var :
[SyncVar (hook="IsDead")]int health = 100;
this is the code that deducts the players health when he gets hit :
[Command]
void CmdWhoWasShot(string uid, int damage)
{
GameObject player = GameObject.Find(uid);
player.GetComponent<Shooting>().DeductDamage(damage);
}
and
public void DeductDamage(int dmg)
{
health -= dmg;
}
(Each player has its own UID)
this is the function “IsDead” :
void IsDead(int hp)
{
if (isLocalPlayer)
{
health = hp;
Debug.Log("Your Health : " + hp);
if (health <= 0)
{
CmdRespawnPlayer(transform.name);
}
}
as you can see , when the player’s health reach 0 , it will call the command CmdRespawnPlayer
[Command]
void CmdRespawnPlayer(string uid)
{
GameObject player = GameObject.Find(uid);
player.GetComponent<Shooting>().health = 100;
player.transform.position = new Vector3(0, 1, 0);
}
now , the player’s health wont be set to 100 , but it will teleport to 0,1,0
why is that and how can I fix that?