Argon Assault - When I call the public method it stops the OnCollision

Adding a scoreboard using a public class to call in another script.

This is the script called ScoreBoard:
public class ScoreBoard : MonoBehaviour
{
int score;

public void IncreaseScore(int amountToIncrease)
{
    score += amountToIncrease;
    Debug.Log($"Score is now: {score}");
}

}

Then I am calling it in my Enemy Script:
public class Enemy : MonoBehaviour
{
[SerializeField] GameObject deathVfx;
[SerializeField] Transform parent;
[SerializeField] int scorePerHit = 15;

ScoreBoard scoreBoard;


void start()
{
    scoreBoard = FindObjectOfType<ScoreBoard>();
}
void OnParticleCollision(GameObject other)
{
    scoreBoard.IncreaseScore(scorePerHit);
    GameObject vfx = Instantiate(deathVfx, transform.position, Quaternion.identity);
    vfx.transform.parent = parent;
    Destroy(gameObject);
}

}

The issue is as soon as I add the line scoreBoard.IncreaseScore(scorePerHit); to enemy.cs , the rest of the collision stops working and I get the error “Object reference not set to an instance of an object”

I did not capitalise the S for void Start.

Problem Solved.

I am a moron.

Thank you for watching.

This sort of thing happens to everyone, so definitely don’t beat yourself up over it! :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms