When adding two numbers, they don't add, they just sit next to each other?
When I am trying to add one score based on distance, and another based on collisions, the two numbers aren't adding together, but are just being put next to each other, where am i going wrong? is it because they are strings?
using UnityEngine; using UnityEngine.UI;
public class score_Banner : MonoBehaviour {
public Transform playerscore;
public Text ScoreText;
void Update () {
ScoreText.text = "Current Score: " + playerscore.position.z.ToString("0") + scoreValue.ToString("0");
}
public static int scoreValue = 0;
Text score;
void Start () {
score = GetComponent<Text> ();
}
}
Answer by pantang · Dec 01, 2019 at 06:57 AM
because you aren't adding them together you are building a string.
you need something like :-
int score; score = playerscore.position.z + scoreValue; ScoreText.text = "Current Score: ";
Answer by arjunpusu · Jul 14, 2020 at 12:12 PM
I also got this error but I changed the variable type int to float and then it worked fine. The position of playerscore is a float value so I think we have to use float instead of int. But I really don't know how to use int for getting the value of position.@hazzapc123