So i have a highscore text that i want to change when the player loses (later i wanna add live score track aswell)
But i cant seem to figure out how to do it, this is the but in the code that are meant to change the highscore text
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class groundController : MonoBehaviour {
public GameObject spawner;
public GameObject greenBall;
public GameObject redBall;
public GameObject yellowBall;
public Text highScoreText;
void Start ()
{
}
void Update ()
{
greenBall = GameObject.FindGameObjectWithTag("greenBall");
redBall = GameObject.FindGameObjectWithTag("redBall");
yellowBall = GameObject.FindGameObjectWithTag("yellowBall");
Debug.Log(yellowBall);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "greenBall")
{
GameOver();
}
else if (other.gameObject.tag == "yellowBall")
{
Destroy(other.gameObject);
}
else if(other.gameObject.tag == "redBall")
{
Destroy(other.gameObject);
}
}
public void GameOver()
{
spawner.GetComponent<gameController>().playable = false;
Destroy(greenBall);
Destroy(redBall);
Destroy(yellowBall);
if (spawner.GetComponent<gameController>().Score > spawner.GetComponent<gameController>().highScore)
{
spawner.GetComponent<gameController>().highScore = spawner.GetComponent<gameController>().Score;
highScoreText = "Highscore: " + spawner.GetComponent<gameController>().highScore;
}
else if(spawner.GetComponent<gameController>().Score == spawner.GetComponent<gameController>().highScore)
{
}
else if(spawner.GetComponent<gameController>().Score < spawner.GetComponent<gameController>().highScore)
{
}
}
void ClearBalls()
{
if(spawner.GetComponent<gameController>().playable == false)
{
Destroy(greenBall);
Destroy(redBall);
Destroy(yellowBall);
}
}
}
I KNOW I KNOW it is gore to a someone that know what they are doing but it works for me.
But i am getting the error "Cannot implicitly convert type ‘string’ to ‘Unity.Engine.UI.Text’ " (Line 54)
Any help here ?