Hi, so I’m new to unity and C# and am trying to add a bonus to my score (score measures the players z position) and really don’t really know how so a little help would be really nice. Heres what I have
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
public Transform player;
public Text scoreText;
private int _score;
private int baseScore;
// Update is called once per frame
void Update()
{
scoreText.text = player.position.z.ToString("0");
if (player.position.y >= 2.5)
{
_score += 50;
scoreText.text = _score.ToString();
Debug.Log(scoreText.text);
// scoreText.text = player.position.z.ToString(scoreText.text + 100);
// scoreText.text = scoreText.text + player.position.z.ToString();
}
// Debug.Log(scoreText.text);
}
}
What happens is that it literally adds 50 to the end. Good luck and thank you!