- Home /
Question by
alexsvensson987 · May 09 at 01:03 AM ·
multiplayer
Respawn Player object after dead in PUN2
I am making multiplayer fighting game using PUN2 and I made dead and respawn function after dead as following code.
public void TakeDamage(int amount)
{
photonView.RPC("Damage", RpcTarget.All, 10);
if (PhotonNetwork.IsMasterClient)
{
StartCoroutine(Respawn());
}
}
[PunRPC]
public void Damage(int amount)
{
Debug.Log("Taking Damage...");
health -= amount;
if (health <= 0)
{
health = 0;
if (true)
{
PhotonNetwork.Destroy(gameObject);
}
}
}
IEnumerator Respawn()
{
yield return new WaitForSeconds(3);
PhotonNetwork.Instantiate("PlayerArmature 1", new Vector3(-16.35f, 19.845f, 40.5966f), Quaternion.identity, 0);
}
When player's health is lower than 0, player destroys, but can't respawn again.
If someone could help with this, that would be thankful.
Thank you.
Comment
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Accessing information and checking who's who in network game. 1 Answer
Photon Bootcamp Multiplayer Demo Room Details... max. Players = 2 ??? 1 Answer
Multiplayer Rigidbody Vibration 2 Answers
Most efficient way to structure a huge online "virtual world" 0 Answers