- Home /
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
Answer by Sospitas · Jul 14, 2014 at 08:20 PM
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 :)
Your answer
Follow this Question
Related Questions
Score display not working 1 Answer
EditorGUI elements require minimum size of 24px? 0 Answers
How to use GUIUtility.hotControl? 0 Answers
Player label appears in sky! 0 Answers
GUI label on raycast? 0 Answers