The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Respawn player game object after dead

ihor
2022-05-09 00:56:43

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.

Comments

Klover
2022-05-09 06:53:17

C# Instantiate in Unity! - Beginner Scripting Tutorial - YouTube

abhishektyagi
2022-05-09 07:13:46

don't destroy the player first when health is 0

disable it and after sometime Increase the health =100

and enable the player and if you want to calculate something after dead like death count and all so then go with the if condition if(health<0)

Back to top