Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[SOLVED]IsPointerOverGameObject???

Discussion in 'Scripting' started by RPP, Dec 13, 2015.

  1. RPP

    RPP

    Joined:
    Nov 11, 2015
    Posts:
    28
    Hello people, i was wondering if it was at all possible to detect if IsPointerOverGameObject with a 'specific' object? for example code below. I receive errors when trying this way, is there a correct way to do this?

    Code (CSharp):
    1. public GameObject myGameObject;
    2.  
    3. void Start()
    4.     {
    5.         myGameObject = GameObject.Find("Lv1");
    6.     }
    7.  
    8. void Update()
    9. {
    10. if(EventSystem.current.IsPointerOverGameObject(myGameObject))
    11. {
    12.      Decrease();
    13. }
    14. }
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    You can use EventSystem.RaycastAll.

    Alternatively you can simply put the various event handlers onto the GameObject of interest.
     
  3. RPP

    RPP

    Joined:
    Nov 11, 2015
    Posts:
    28
    ahh good idea, ill simply add the eventHandler to the object i want used. Thanks!
     
    Kiwasi likes this.