Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

raycast and raycasthit for mouse selection

Discussion in 'Editor & General Support' started by felipi arena, Jun 10, 2010.

  1. felipi arena

    felipi arena

    Joined:
    Jun 7, 2010
    Posts:
    25
    Hi,

    what i want to do is to know witch object my mouse is over, and to do that i'm using raycast.

    What to compare the collider of the point that i hit with collider from other objects, like:

    if (hit.collider==object.collider){
    }

    the problems is, sometimes even when my mouse is over a certain object, that expression keep returning false, don't know why tough.

    I don't think this is the best aproach for doing this, but it's the best i could think, so please if anyone know any other solution, or know why mine is not working sometimes, please notice me.

    thanks!
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Can you post the whole of the script you are using for this? One possibility is that there may be another collider in between the ray origin and the target, for example, if you are casting a ray from the centre of an object which has a collider itself.
     
  3. felipi arena

    felipi arena

    Joined:
    Jun 7, 2010
    Posts:
    25
    Oh, this aproach was right. It's like this that it should be done, it was i who was messing up!

    But it's better to us hit.collider.gameObject.
     
unityunity