Hey there I`ve seen some people with the same problem that I’m having… a NullReferenceException, but none of them solved mine…
Here are some bits of information:
//EnemyBehaviour score information:
public int scoreValue = 120;
private ScoreKeeper scoreKeeper;
//where the error occurs
void Start()
{
scoreKeeper = GameObject.Find("Score").GetComponent<ScoreKeeper>();
}
//Enemy Death method
private void OnTriggerEnter2D(Collider2D collider)
{
Projectile missile = collider.gameObject.GetComponent<Projectile>();
if (missile)
{
health -= missile.GetDamage();
missile.Hit();
if(health <= 0)
{
Destroy(gameObject);
scoreKeeper.Score(scoreValue);
}
}
}
//ScoreKeeper Method
public int score = 0;
public Text myText;
void Start()
{
myText = GetComponent<Text>();
Reset();
}
public void Score(int points)
{
score += points;
myText.text = score.ToString();
}
public void Reset()
{
score = 0;
myText.text = score.ToString();
}
Prints