My Scoreboard Is Broken

Hello,

I dont know what happened but my scoreboard is not working. Anybody has any idea what might have happened ?

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ScoreBoard : MonoBehaviour
{
int score;
Text scoreText;
void Start()
{
scoreText = GetComponent();
scoreText.text = score.ToString();
}
public void ScoreHit(int scoreIncrease)
{
score = score + scoreIncrease;
scoreText.text = score.ToString();
}
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy : MonoBehaviour
{
[SerializeField] int hits = 10;
[SerializeField] int scoreIncrease = 12;
[SerializeField] GameObject enemyDeathFX;
[SerializeField] Transform parent;
ScoreBoard scoreBoard;
void Start()
{
AddBoxCollider();
scoreBoard = FindObjectOfType();
}

private void AddBoxCollider()
{
    Collider enemyBoxCollider = gameObject.AddComponent<BoxCollider>();
    enemyBoxCollider.isTrigger = false;
}  
private void OnParticleCollision(GameObject other)
{
    ProcessHit();
    if (hits <= 0)
    {
        KillEnemy();
    }
}
private void ProcessHit()
{
    scoreBoard.ScoreHit(scoreIncrease);
    hits--;
}
private void KillEnemy()
{
    GameObject fx = Instantiate(enemyDeathFX, transform.position, Quaternion.identity);
    fx.transform.parent = parent;
    Destroy(gameObject);
}

}

Hey Loch,

It looks like Ben addresses this issue in the beginning of video 108.

1 Like

@Lochnload Thanks man, had the same problem. I knew Ben had explained but couldn’t remember which video. I appreciate your help!!

Privacy & Terms