My respawning script isn't working
My respawning script isn't working anymore, and I have no clue why. It mainly seemed to stop working when I added multiplayer. Now what happens when I die is it just deletes the player, and it doesn't restart. I'm using this in unity 5.6.
using UnityEngine; using System.Collections;
public class RestartScene : MonoBehaviour {
bool restarting = false;
EntityStats[] playersStats;
void Start() {
var players = GameObject.FindGameObjectsWithTag("Player");
playersStats = new EntityStats[players.Length];
for(int i = 0;i < players.Length;i ++) {
playersStats[i] = players[i].GetComponent<EntityStats>();
}
}
void Update() {
if(restarting) return;
foreach(var player in playersStats) {
if(player.health <= 0) {
restarting = true;
StartCoroutine("RestartSceneC");
break;
}
}
}
IEnumerator RestartSceneC() {
yield return new WaitForSeconds(5);
Application.LoadLevel(1);
}
}
Edit: I figured out my problem, but still need help fixing it. The script basically says "if player health=0 then restart the scene", but with multiplayer added a player isn't originally in the scene, it is spawned by hitting the "local host" button to start a game. No clue how to solve this
Your answer
Follow this Question
Related Questions
ClientRpc not functioning 0 Answers
Hosting my localhost game online? 0 Answers
[uNet] Multiple Spawnpoints with Selection 0 Answers
uNet. Spawning objects over the network. 0 Answers
HELP with Unity Networking 0 Answers