Hello, I am currently trying to make a side scrolling space shooter and current implementing a scoring system. At the moment I have two things that spawn. An enemy and an asteroid.
I have got my scripts working individually. So essentially when I destroy an enemy it sends a number to the GUIText and then when destroying an asteroid it sends a number to the same GUIText.
I am trying to make it so that the GUIText both adds up the enemies and asteroids score. Could anyone help?
Thank you!
(Some sample code)
using UnityEngine;
using System.Collections;
public class ScoreController : MonoBehaviour {
public GUIText scoreText;
private int score;
void Start()
{
score = 0;
}
public void AddScore(int newScoreValue)
{
score += newScoreValue;
UpdateScore();
}
void UpdateScore()
{
scoreText.text = "Score: " + score;
}
}
void Start()
{
GameObject gameControllerObject = GameObject.FindWithTag("GameController");
if(gameControllerObject != null)
{
gameController = gameControllerObject.GetComponent <ScoreController>();
}
else if(gameControllerObject == null)
{
Debug.Log ("Could not find game object controller.");
}
}