Hi all,
I’m trying to display the data in the variable “playerScore” from the script “ScoringAndEnemyDestroy”. I want the data from “playerScore” to be placed in the variable “totalScore” in the script “ScoreGUI” so I can display that data as a GUI. The GUI cannot be created in the “ScoringAndEnemyDestroy” script as the GUI repeats itself multiple times as the script is used on multiple colliders.
public class ScoringAndEnemyDestroy : MonoBehaviour {
public long playerScore;
// Use this for initialization
void Start () {
}
// Update is called once per frame
public void Update () {
PlayerScore ();
}
public void OnTriggerEnter(Collider other){
Debug.Log ("Entering collider");
if (other.gameObject.tag == "Enemy") {
Destroy (other.gameObject);
playerScore += 5;
if (other.gameObject.tag == "Boss")
Destroy (other.gameObject);
playerScore += 10;
}
}
void PlayerScore()
{
SendMessage ("TotalScore", playerScore, SendMessageOptions.DontRequireReceiver);
}
}
public class ScoreGUI : MonoBehaviour {
public long totalScore;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void TotalScore (long playerScore)
{
Debug.Log("PlayerScore: " +playerScore);
if (playerScore > 0)
playerScore = totalScore;
Debug.Log ("Total score is being calculated: " + totalScore);
}
void OnGUI() {
GUI.TextArea (new Rect (25,25,50,50), totalScore.ToString());
}
}
All help is greatly appreciated,
Many thanks