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);
}
}