Hey everyone, I’m trying to get a scoreboard working in my game by having a score keeper store and print vars to the console (For Now) and whenever the code tries to add to the integers “blueScore” and “redScore” I get this error “NullReferenceException: Object Reference not set to an Instance of an object…” Anyone have an idea why this is happening?
void Update () {
if (thisObject.position.y < deathHeight)
{
if (randomRespawn)
{
rangeX = Random.Range(minX, maxX);
rangeY = Random.Range(minY, maxY);
rangeZ = Random.Range(minZ, maxZ);
respawnPosition = new Vector3(rangeX, rangeY, rangeZ);
}
rigidObject.velocity = new Vector3(0, 0, 0);
thisObject.position = respawnPosition;
if (this.name == "Player")
{
GetComponent<scoreKeeper>().redScore++;
}
if (this.name == "Enemy")
{
GetComponent<scoreKeeper>().blueScore++;
}
}