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. Dismiss Notice

Was object hit by a ray

Discussion in 'Scripting' started by Deleted User, Jul 27, 2016.

  1. Deleted User

    Deleted User

    Guest

    Is there a way to check if an object was hit by a ray rather than if a ray hit an object?

    I want an event to be triggered when a player presses a button, and I want the button to be that "object".
     
  2. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    you do the same method as you would check to see that object, but in the end you could broadcast a message to that object stating that it was hit.

    It is probably better to do it the conventional way.
     
    Kiwasi likes this.
  3. Zaflis

    Zaflis

    Joined:
    May 26, 2014
    Posts:
    438
    Add OnMouseDown event on C# script of the object, and it should detect click. Some use raycasts, but since it will be done internally anyway you might aswell use the events made by Unity.
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    This. Except you should be using the EventSystem OnPointerXXX interfaces instead of OnMouseXXX.