Hello everyone,
I want to know if there is a possibility to make a GUI.Button return true when the user immediately press on it, not click (press and release)
Am making a game for Android and it’s weird to have such an effect with buttons.
Am sure there is a simple solution for this, otherwise i had to make it manually
Thank you
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour
{
bool pressed = false;
GUIContent btn;
int presses = 0;
void Start()
{
btn = new GUIContent("Test");
}
void Update()
{
if(Input.GetMouseButtonUp (0))
pressed = false;
}
void OnGUI()
{
if(GUILayout.RepeatButton(btn))
{
if(!pressed)
{
presses++;
pressed = true;
}
}
GUILayout.Label(presses.ToString ());
}
}
Use GUI.RepeatButton:
if(GUI.RepeatButton(new Rect(0,0,50,20),"Repeat")){
...}
there is an easy way:
in the inspector of the button, add component - > event trigger and then you can add there → add new event type and you cand find the pointer down event