am i doing wrong?
i want to the score increase on text UI when the object was destroyed, but when the object was destroyed, the score isn’t increase or change.
int score = 0;
public Text ScoreText;
void Start()
{
ScoreText.text = "Score: " + PlayerPrefs.GetInt("myScore");
}
void Update()
{
for (var i = 0; i < Input.touchCount; ++i)
{
if (Input.GetTouch(i).phase == TouchPhase.Began)
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
if (Physics.Raycast(ray, out hit))
Destroy(hit.collider.gameObject);
score += 1;
PlayerPrefs.SetInt("myScore", score);
}
}
}
}
i have already assign the text UI on inspector of the object which i attached this script.