Object reference not set to an instance of an object

Updated on October 30, 2017 in [A] C# .Net
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on October 30, 2017

how can i solve

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

public class Score : MonoBehaviour {
private float score = 0.0f;
private int difficultyLevel = 1;
private int maxDifficultyLevel = 10;
private int scoreToNextLevel = 10;
public Text scoreText;

// Update is called once per frame
void Update () {
if (score >= scoreToNextLevel)
LevelUp ();
score += Time.deltaTime * difficultyLevel;
scoreText.text = ((int)score).ToString();
}
void LevelUp()
{
if (difficultyLevel == maxDifficultyLevel)
return;
scoreToNextLevel *= 2;
difficultyLevel++;
GetComponent<PlayerMotor>().SetSpeed (difficultyLevel);
Debug.Log (difficultyLevel);
}
}

  • Liked by
Reply
0 on October 30, 2017

Are you sure that you have assigned the scoreText variable a reference in the editor? And is a player motor as a component on the score object? Could you give us the line in which the error occurs?

  • Liked by
Reply
Cancel