I have problem because I can't read a static value added to Uptade() and use it.
Rock
[Header("Points")]
public TextMeshProUGUI points;
public static int point;
private void Start()
{
points = GetComponent<TextMeshProUGUI>();
}
void Update()
{
Move();
}
void Move()
{
point = 1;
Debug.Log(point);
}
Points
[Header("Points")]
public TextMeshProUGUI points;
public Rock countPoint;
void Start()
{
}
void Update()
{
Debug.Log("points" countPoint.point);
}
I want to see this point in class points. If i will delete static then debug showing just 0. Can you show me how to do it in correct way in full example ? or reedit my code.
CodePudding user response:
Static variables/functions can directly be accessed by class name. So, Rock.point would do.
CodePudding user response:
You're trying to access a static member by using an object reference.
Instead of using an instance of the object:
Debug.Log("points" countPoint.point);
You should be using using the class to call the field:
Debug.Log("points" Rock.point);