I having problems with unity mirror. When respawn IEnumerator is called, the player respawn but it disconnect from the server, he cant move (only locally) and he cant do commands. this is the respawn code:
using UnityEngine;
using Mirror;
using System.Collections;
public class LaserGun : NetworkBehaviour
{
public Transform laserTransform;
public LineRenderer line;
// Update is called once per frame
void Update()
{
if(isLocalPlayer && Input.GetKeyDown(KeyCode.Q)){
CmdShoot();
}
}
[Command]
public void CmdShoot(){
Ray ray = new Ray(laserTransform.position, laserTransform.forward);
if(Physics.Raycast(ray, out RaycastHit hit, 100f)){
print(hit.collider.gameObject);
if(hit.collider.gameObject.tag == "Player"){
print("player checked as a player");
StartCoroutine(Respawn(hit.collider.gameObject));
}
print(hit.collider.tag);
RpcDrawLaser(laserTransform.position, hit.point);
}
else{
RpcDrawLaser(laserTransform.position, laserTransform.position + laserTransform.forward * 100f);
}
}
[Server]
IEnumerator Respawn(GameObject go){
print("Player ded");
NetworkServer.UnSpawn(go);
yield return new WaitForSeconds(0.5f);
NetworkServer.Spawn(go);
}
[ClientRpc]
void RpcDrawLaser(Vector3 start, Vector3 end){
StartCoroutine(LaserFlash(start, end));
}
IEnumerator LaserFlash(Vector3 start, Vector3 end){
line.SetPosition(0, start);
line.SetPosition(1, end);
yield return new WaitForSeconds(0.3f);
line.SetPosition(0, Vector3.zero);
line.SetPosition(1, Vector3.zero);
}
}
Any solutions to that problem please?