I have a scene to which I’ve added the standard assets FPS Controller - it all works great but I want to add a separate Game Manager script that I can make calls to for end game, restart game, etc (still learning a lot of this.)
My GameManager.cs file to start with is this:
using System;
using UnityEngine;
namespace UnityStandardAssets.Characters.FirstPerson
{
public class GameManager : MonoBehaviour
{
public void RestartGame()
{
Debug.Log(“GAME RESTART”);
}
}
}
And in the FirstPersonController.cs file I’ve added this line:
FindObjectOfType().RestartGame();
I think the namespaces are set up correctly as the editor recognizes both the GameManager type and the RestartGame procedure.
However, when I run the game and it gets to that line I get this error:
NullReferenceException: Object reference not set to an instance of an object
UnityStandardAssets.Characters.FirstPerson.FirstPersonController.FixedUpdate () (at Assets/Standard Assets/Characters/FirstPersonCharacter/Scripts/FirstPersonController.cs:162)
The Game Controller object is in the scene but not sure what I am doing wrong, any ideas?