using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
public Transform Player;
public Text ScoreText;
void Update()
{
Player = GetComponent();
ScoreText = GetComponent();
ScoreText.text =Player.position.z.ToString(“0”);
}
}
Problem:Score doesn’t change,always 0(Score will increase depends player’s z move foward)
Where can i fix it?
Use code tags when posting code.
I assume that this script is not attached to your player object while simultaneously being attached to your Text object in the UI (because that would be nonsense). GetComponent<> finds the component of that type -on this object-.
If you remove the two GetComponent lines, then select this object and look at it in the inspector, you can drag different objects into the slots for those variables. Drag your text object into the ScoreText slot and your player object into the Player slot.