P
P
Pavel Subbotin2021-01-12 22:07:37
Unity
Pavel Subbotin, 2021-01-12 22:07:37

Why is the button not responding to clicks?

In general, according to the video, I wrote the following script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class buttonClick : MonoBehaviour, IPointerDownHandler, IPointerUpHandler 
{
    public void OnPointerDown(PointerEventData eventData) {
        if(gameObject.name == "right") {
            GameObject.FindWithTag("Player").GetComponent<Player>().move = 1;
        }else if(gameObject.name == "left") {
            GameObject.FindWithTag("Player").GetComponent<Player>().move = -1;
        }
        Debug.Log(GameObject.FindWithTag("Player").GetComponent<Player>().move);
    }

    public void OnPointerUp(PointerEventData eventData) {
        GameObject.FindWithTag("Player").GetComponent<Player>().move = 0;
    }
}

But the buttons just don't respond to my clicks, what should I do?
5ffdf36e58715071488169.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question