GUI.Label, text plus user variables

EDIT:

Updated the code in the question which now contains the answer

I want to determine the number of fingers a user has on screen using GUI.Label, my code below:

using UnityEngine;
using System.Collections;

public class fingerCount : MonoBehaviour {

    int fingerCounter = 0;

	// Use this for initialization
	void Start () 
	{
	
	}
	
	// Update is called once per frame
	void Update () 
	{
		
		foreach (Touch touch in Input.touches) 
		{
			if(touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
			{
				fingerCounter++;
			}
		}

	}

	void OnGUI()
	{
		if (fingerCounter > 0) 
		{
			GUI.Label (new Rect (0, 0, Screen.width, Screen.height), "User has " + fingerCounter.ToString() + " finger(s) touching the screen");
		}
	}

	
}

The if statement in the OnGUI() function is incorrect but is there a way so that i can make it correct so that the label will update on screen with each finger I add?

Cheers in advance

In the label, change fingerCount to fingerCount.ToString().

Oh, and make the fingerCount variable a class variable, not local to the function, otherwise the OnGUI won’t be able to access it

That should fix it for you :slight_smile: