Skip to main content
added 263 characters in body
Source Link
Tribski
  • 155
  • 4
  • 10

A common problem in Unity - my OnMouseUpAsButton() is not being called, and I do not understand why. I have attached box collider 2d (though its size is set up during runtime, but by the time I click on it it has proper size and covers the whole button). My object is an UI element, created from prefab during runtime. Here you can see its inspector info:

enter image description here

Code:

using UnityEngine;
using System.Collections;

public class button_controller : MonoBehaviour {
void OnMouseUpAsButton()
{
    Debug.Log("Clicked event button");
    switch(click_action){
        case action.NONE:
            action_none();
            break;
    }
}

I tried going through other threads where people had similar problems but nothing seems to work. Any ideas what might be happening?

EDIT: I found out that if I add a new button , directly from the inspector to the canvas, whose collider is within the canvas all other buttons start working. Interestingly I cannot put this new button anywhere, it has to be at least a bit within the canvas

A common problem in Unity - my OnMouseUpAsButton() is not being called, and I do not understand why. I have attached box collider 2d (though its size is set up during runtime, but by the time I click on it it has proper size and covers the whole button). My object is an UI element, created from prefab during runtime. Here you can see its inspector info:

enter image description here

Code:

using UnityEngine;
using System.Collections;

public class button_controller : MonoBehaviour {
void OnMouseUpAsButton()
{
    Debug.Log("Clicked event button");
    switch(click_action){
        case action.NONE:
            action_none();
            break;
    }
}

I tried going through other threads where people had similar problems but nothing seems to work. Any ideas what might be happening?

A common problem in Unity - my OnMouseUpAsButton() is not being called, and I do not understand why. I have attached box collider 2d (though its size is set up during runtime, but by the time I click on it it has proper size and covers the whole button). My object is an UI element, created from prefab during runtime. Here you can see its inspector info:

enter image description here

Code:

using UnityEngine;
using System.Collections;

public class button_controller : MonoBehaviour {
void OnMouseUpAsButton()
{
    Debug.Log("Clicked event button");
    switch(click_action){
        case action.NONE:
            action_none();
            break;
    }
}

I tried going through other threads where people had similar problems but nothing seems to work. Any ideas what might be happening?

EDIT: I found out that if I add a new button , directly from the inspector to the canvas, whose collider is within the canvas all other buttons start working. Interestingly I cannot put this new button anywhere, it has to be at least a bit within the canvas

Source Link
Tribski
  • 155
  • 4
  • 10

OnMouseUp not working in unity

A common problem in Unity - my OnMouseUpAsButton() is not being called, and I do not understand why. I have attached box collider 2d (though its size is set up during runtime, but by the time I click on it it has proper size and covers the whole button). My object is an UI element, created from prefab during runtime. Here you can see its inspector info:

enter image description here

Code:

using UnityEngine;
using System.Collections;

public class button_controller : MonoBehaviour {
void OnMouseUpAsButton()
{
    Debug.Log("Clicked event button");
    switch(click_action){
        case action.NONE:
            action_none();
            break;
    }
}

I tried going through other threads where people had similar problems but nothing seems to work. Any ideas what might be happening?