Brackeys / MultiplayerFPS-Tutorial

A video series on making a multiplayer first-person shooter in Unity.
The Unlicense
654 stars 287 forks source link

respawn error/freeze/crash (Another NullReferenceException) #12

Open brikthor opened 7 years ago

brikthor commented 7 years ago

Respawn works find when hard coded, and VS seems to recognize that the field is a float value.

NullReferenceException: Object reference not set to an instance of an object Player+c__Iterator0.MoveNext () (at Assets/Scripts/Player.cs:83)

Said Line: yield return new WaitForSeconds(GameManager.instance.matchSettings.respawnTime);

looks like everything is spelled properly, I went into the code and compared all the lines to what I have by copying them into my project and using the Find feature to paste, no discrepancies found.

MatchSettings looks like: [System.Serializable] public class MatchSettings {

public float respawnTime = 3f;

}

GameManager (minus Player Tracking field):

using UnityEngine; using System.Collections.Generic;

public class GameManager : MonoBehaviour {

public static GameManager instance;

public MatchSettings matchSettings;

void Awake ()
{
    if (instance != null)
    {
        Debug.LogError("More than one GameManager in scene.");
    } else
    {
        instance = this;
    }
}