- Home /
Functions aren't appearing in the onClick editor.....
First, here's the code which I had typed. The function 'goFront' should correspond to a button present on the screen to move the object forward.
public class playerCon : MonoBehaviour
{
public GameObject testPlayerVar;
public float speed = 10f;
public void goFront(PointerEventData event)
{
if(event.pointerPress == true)
{
testPlayerVar.transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
else
{
testPlayerVar.transform.Translate(Vector3.zero);
}
}
}
Problem is, I attached the script to the Canvas so that I could access the function from the respective button, and I can see the script name in the onClick editor, but I'm not able to see my function. Help!
Answer by Captain_Pineapple · Jul 06, 2020 at 07:30 AM
If i remember correctly you can only have no argument or 1 string argument.
PointerEventData is just not valid in this context thus the function is not shown.
Since the button is handling the click detection for you, it does not pass on the event data. Just remove the parameter from the function. There is no need for the check you are doing on it, as the button does that for you.
basically this. The function is a callback. It will trigger once it is "clicked". To detect if there is a button release you have to add a second function which is then connected to the "onRelease" event.