Hey guys, i would like to show high score value at high score text, but im getting this error.
Assets/Scripts/Score.cs(24,46): error CS0030: Cannot convert type float' to
string’
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Score : MonoBehaviour
{
public Text scoreText;
public Text endGame;
public Text saniye;
public float myTimer = 0.0f;
public float life;
public Text highScoreText;
public float highScore = 0;
string highScoreKey = "HighScore";
void Start()
{
scoreText = GetComponent<Text>();
endGame.text = "";
saniye.text = "";
highScore = PlayerPrefs.GetInt(highScoreKey,0);
highScoreText.text = (string)highScore;
}
void Update()
{
life = healthBar.cur_health;
if (life > 0) {
myTimer += Time.deltaTime;
Debug.Log("life < 0");
scoreText.text = Mathf.Round(myTimer).ToString();
}
if (life < 0) {
Debug.Log("life < 0");
endGame.text = Mathf.Round(myTimer).ToString();
scoreText.text = "";
saniye.text ="Secs Alive";
if(myTimer>highScore){
PlayerPrefs.SetInt(highScoreKey, (int)myTimer);
PlayerPrefs.Save();
}
}}
}