So I am learning Unity and Game Development and wrote a script for scoring using UnityEngine.UI Text.
This is my Score.cs code
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
public static Text currentScore;
// Start is called before the first frame update
void Start()
{
int initalScore = 0;
currentScore.text = initalScore.ToString();
}
public static void IncreaseScore()
{
int Score = int.Parse(currentScore.text);
Score++;
currentScore.text = Score.ToString();
}
// Update is called once per frame
void Update()
{
}
}
I am calling Increase Score from Obstacle Script like this:
if(transform.position.x >= player.position.x + 5f)
{
transform.position = transform.position + offset;
Score.IncreaseScore();
}
But Inspector not showing currentScore variable thus I am unable to assign my text object to it.
Please help on what to do.