Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Particles on left click (need help)

Discussion in 'Scripting' started by BOMBA1337, Aug 24, 2016.

  1. BOMBA1337

    BOMBA1337

    Joined:
    Aug 24, 2016
    Posts:
    2
    Hi guys i want to attach my particle system to the mouse cursor so every time i make a left click it should show a particle for some time at the point of the cursor.

    So but i got a problem how do i get the mouse position and play the particle at this point where the cursor is?

    Code (csharp):
    1.  
    2.         if(Input.GetMouseButtonDown(0))
    3.         {
    4.             //Need to get the mouse position here
    5.             cursoreffect.Play(); //and play the particle effect at this position for 0.2 seconds or something
    6.         }
    7.  
    Hope i'm in the right section for this question, thanks.

    Already checked documentation but didn't find something for the problem i think.
     
  2. chubbspet

    chubbspet

    Joined:
    Feb 18, 2010
    Posts:
    1,220
    You will need to use ScreenToWorldpoint like this

    Code (CSharp):
    1. Vector3 position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    Look at that documentation and let us know if you still cant get it working.
     
  3. BOMBA1337

    BOMBA1337

    Joined:
    Aug 24, 2016
    Posts:
    2
    Hi thanks for you reply.
    The effect is working correctly now.
    If it matters i'm using a canvas with screen space camera the effect is not following the cursor correctly.

    I don't get it how i can set the new cursor location after i got the mouseInput to the camera.
    So it is always in the center of screen don't following the cursor.

    //EDIT: I got it - thanks for you help all. <<
     
    Last edited: Aug 24, 2016