Search Unity

does the pointer collide on the particle?

Discussion in 'Scripting' started by gokhanertem, Mar 1, 2010.

  1. gokhanertem

    gokhanertem

    Joined:
    Aug 31, 2009
    Posts:
    95
    hi,
    i have made a particle system in which all the particles are placed to the screen via XML data, i mean all the particles have a predefined position.

    What i want to do is to know if the mouse is on one of the particles or not . i want to display different information about these particles, so i need to know which one of te particle index is being collided.

    there are some physics.raycast functions, however i don no what to do know.

    thank you in advance...
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    You probably don't need to do a raycast for this. You can use Camera.WorldToScreenPoint to convert each particle's world location to its position onscreen. Then, just check to see if it is within acceptable range of the mouse position.
     
  3. gokhanertem

    gokhanertem

    Joined:
    Aug 31, 2009
    Posts:
    95
    did that
    however for 100+ particles my computer started to show slow downs..
    is there a faster way?
    I tried to change particles into cameraoriented sprites, maybe i can try a mouse to object projection?

    i just dont know which fuctions to try out now...
     
  4. Flimgoblin

    Flimgoblin

    Joined:
    Nov 25, 2009
    Posts:
    89
    No idea if this would be any faster, but you could try creating a non-rendering sphere/box collider which moves with the mouse pointer, and turn on the particle collider + collision messages for the particles.

    Not sure how that'd work with the z axis though.