Respawn player game object after dead
The whole answer can be found below.
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).
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
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