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

Physics Raycaster - Selected Object

Discussion in 'Scripting' started by RussellT, Apr 15, 2015.

  1. RussellT

    RussellT

    Joined:
    Feb 1, 2015
    Posts:
    18
    Hello All,

    How do I make my Physiscs Raycaster the object I have clicked on?

    If I set 'First Selected' to be an object, and then click on another object it does then move to 'Last Selected' so I that side of it is working, Just not sure where I need to be telling it....

    Thanks,
    Russell
     

    Attached Files:

  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    The RaycastHit that you pass into the Physics.Raycast function has that information via the collider property.

    Code (csharp):
    1.  
    2. Debug.Log("I hit: " + raycastHit.collider.GameObject);
    3.  
    Or are you asking for something else? I get the feeling there's a slight language barrier.
     
  3. RussellT

    RussellT

    Joined:
    Feb 1, 2015
    Posts:
    18