How do I make the Score system work?
I do the tutorial score manager but when I do everything it does not work. PLEASE HELP.
Here's the Enemy Health -
using System.Collections;
using UnityEngine;
public class EnemyHealthManager : MonoBehaviour {
public int MaxHealth;
public int CurrentHealth;
public int scoreValue = 10;
// Use this for initialization
void Start()
{
CurrentHealth = MaxHealth;
}
// Update is called once per frame
void Update()
{
if (CurrentHealth <= 0)
{
Destroy(gameObject);
}
}
public void HurtEnemy(int damageToGive)
{
CurrentHealth -= damageToGive;
}
public void SetMaxHealth()
{
CurrentHealth = MaxHealth;
}
public void Scoring()
{
ScoreManager.score += scoreValue;
}
}
Here's the ScoreManger -
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class ScoreManager : MonoBehaviour
{
public static int score;
Text text;
void Awake()
{
text = GetComponent<Text>();
score = 0;
}
void Update()
{
text.text = "Score: " + score;
}
}
Answer by eatsleepindie · Apr 12, 2017 at 04:28 PM
You aren't calling the 'Scoring()' function from anywhere that I can see. If you want the score to increase when the player damages an enemy, you will need to call that function in the 'HurtEnemy()' function.
public void HurtEnemy(int damageToGive)
{
CurrentHealth -= damageToGive;
Scoring();
}
Only Update(), Start() and Awake() are automatically called in your script (Unity handles this for you). Any custom function you write will need to be called from somewhere or it will simply sit there and do nothing.
Your answer
Follow this Question
Related Questions
Problem with counting score in 3D game 1 Answer
How do I add a score system? 1 Answer
Problem with ScoreBoard in Ping Pong game 1 Answer
How do I make a score system? 1 Answer
Scoring different amount of points 0 Answers