this is my problem and have made this super simple i just need to know why it doesnt work and how to fix it i cant work it out
i have a scene with a game manager that i dont want to destroy on load that works fine
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour {
public static GameManager Instance;
public int score;
public void Awake()
{
DontDestroyOnLoad(this.transform.gameObject);
SceneManager.LoadScene("Game");
}
}
in the game scene i want it to plus one and print to the debug.log
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlusOne : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
private void FixedUpdate()
{
GameManager.Instance.score = GameManager.Instance.score + 1;
Debug.Log(GameManager.Instance.score);
}
}
but instead i just get an error saying
NullReferenceException: Object reference not set to an instance of an object
PlusOne.FixedUpdate () (at Assets/PlusOne.cs:19)
can anyone help