Search Unity

Raycaster hit position

Discussion in 'Scripting' started by Sean-Powell, Apr 25, 2015.

  1. Sean-Powell

    Sean-Powell

    Joined:
    Dec 18, 2014
    Posts:
    87
    Hi,

    I am using a Physics.Raycast to tell if the player is pointing at a object, and i can not think of a way to return the object that it hit. So i can add a item to the object.
     
  2. Thibault-Potier

    Thibault-Potier

    Joined:
    Apr 10, 2015
    Posts:
    206
    Code (CSharp):
    1. if (Physics.Raycast (position, target, out raycastHit)) {
    2.             return raycastHit.collider.gameObject;
    3. }
     
  3. Sean-Powell

    Sean-Powell

    Joined:
    Dec 18, 2014
    Posts:
    87
    thanks