A
A
Armyashka2019-12-10 19:42:51
C++ / C#
Armyashka, 2019-12-10 19:42:51

Why is the OnMouseUpAsButton function not working?

I have a UI button. I need it to decrease its size when the mouse button is released. I have attached the following script:

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

public class GG : MonoBehaviour
{
    public void OnMouseUpAsButton()
    {
        transform.localScale = new Vector3(0.7f, 0.7f, 0.7f);
    }
}

When the button is pressed, nothing happens.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Gaydak, 2019-12-10
@MrMureno

for starters, read here
https://docs.unity3d.com/ru/current/ScriptReferenc...
then from the lessons somewhere you should have figured out that in order for events to fire, they must be present in the
EventSystem scene (generate all these events actually)
GraphicRaycast (on the canvas, in order to know that events are needed for this menu, if we simplify it a lot)
on some of the button elements, there should be a Raycast target checkbox (on the text, background or any other graphic, to mark it as PRESSED conditionally)
well, do not forget that all this can still work in layers if suddenly changed from the default.
but in general it would be worthwhile to apply screenshots of the hierarchy and the inspector, so that you can see what the button is and what you have in the scene.

A
Armyashka, 2019-12-10
@Armyashka

I have all of the above elements of the scene.
Where should the checkbox be checked: on some component of the button or on its child object?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question