Added a script to a gameObject, but doesn't work.

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

public class onClick1 : MonoBehaviour
{
    public bool mouseDown1;
    // Start is called before the first frame update
    void Start()
    {
       
    }

    private void OnMouseOver()
    {
        Debug.Log("Test");
    }
    private void OnMouseDown()
    {
       
    }
    // Update is called once per frame
    void Update()
    {
       
    }
}

The object that have the script attached to is a UI Image. No idea why doesn’t it detect.

this would be too easy :smile:

I think, OnMouseOver don’t works with UI. Try to add “Event Trigger” as component to the image. Then add new event type “Pointer Enter”. Select Image in it and the public function that should be executed.

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

public class onClick1 : MonoBehaviour
{
    public bool mouseDown1;
    // Start is called before the first frame update
    void Start()
    {

    }

    public void OnSomethingOver ()
    {
        Debug.Log("Test");
    }

    private void OnMouseOver()
    {
       
    }
    private void OnMouseDown()
    {

    }
    // Update is called once per frame
    void Update()
    {

    }
}