C# Display Int Var value into a GUI.Text for Score

Hey Guys, Learning C# at the moment and creating a mini game. Everything done and works fine but i would like to add a score system.

I have tried a few ways as displayed here but don’t seem to get it to work but wonder if i’m on the right lines.

I’m looking to get the a public int Var Value that counts the number of hits, this works fine in game and can see it counting. I would like this to be displayed on a GUI.Text within the game like score display.

Far as i understand, this should work below


GUI.Text = GameManager.Hits.ToString;


As only want to display the public int var in the GUI.text or have i missed the plot here?

GUI.Text = GameManager.Hits.ToString();

ToString() is a function.

Great, thanks so much Dimling. If you can tell me how to thumb u up i would lol.

Code that works:

using UnityEngine;
using System.Collections;

public class score : MonoBehaviour {	
	
void OnGUI()
{
    GUILayout.Label( "Score = " + GameManager.Hits);
}	
}

using UnityEngine;
using System.Collections;

public class GameManager : MonoBehaviour 
{
	
	//Total number of hits
	public static int Hits = 0;

Works a treat, thank you guys :smiley: