I’m trying to make an instance and it isn’t happening.
Error I’m getting :
NullReferenceException: Object reference not set to an instance of an object
Score.AddPoint () (at Assets/Score.cs:11)
ScorePoint.OnTriggerEnter2D (UnityEngine.Collider2D collider) (at Assets/ScorePoint.cs:8)
using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour {
static int score = 0;
static int highScore = 0;
static Score instance;
static public void AddPoint(){
if (instance.bird.dead)
return;
score++;
if (score > highScore) {
highScore = score;
}
}
BirdMovement bird;
void Start(){
instance = this;
score = 0;
GameObject player_go = GameObject.FindGameObjectWithTag ("PlayerBird");
if (player_go == null) {
Debug.LogError ("Could not find an object with tag 'Plyaerbird'!");
}
bird = player_go.GetComponent<BirdMovement> ();
highScore = PlayerPrefs.GetInt ("highScore", 0);
}
void OnDestroy(){
instance = null;
PlayerPrefs.SetInt ("highScore", highScore);
}
void Update () {
guiText.text = "" + score;
}
}