I am making a game that has a scoring system but it doesn’t work. I am trying to make it where if the enemy dies the player gets 10 points and so on. So, I made a GUIText to display the score and made a script with the following:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
public GUIText scoreText;
private int score;
void Start()
{
score = 0;
Update();
}
public void AddScore(int newScoreValue)
{
score += newScoreValue;
Update();
}
void Update()
{
scoreText.text = "Score: " + score;
}
}
and on the enemy side, I put the next following script so it can die when hit and to scores a point but it doesn’t work.
using UnityEngine;
using System.Collections;
public class Damagebycrash : MonoBehaviour {
int health = 1;
public int scoreValue;
private Score score;
void OnTriggerEnter2D(Collider2D collider) {
if(collider.tag == "Invaders"){
score.AddScore(scoreValue);
}
Debug.Log("Trigger!!");
health--;
if (health <= 0) {
Die();
}
}
void Die()
{
Destroy(gameObject);
}
}
so yeah please help me?