Unity 3D Game Engine – Particles follow Cursor Pointer
1. MAIN TOP MENU> Main Object> Create Other> Particle System
2. Inspector> Particle System> Add Component> New Script> FollowMouse.JS
3. FollowMouse.JS
#pragma strict function Start () { Screen.showCursor = false; } // ------------------------------- // FOLLOW MOUSE POSITION START // ------------------------------- public var depth = 10.0; function FollowMousePosition() { var mousePos = Input.mousePosition; var wantedPos = Camera.main.ScreenToWorldPoint (Vector3 (mousePos.x, mousePos.y, depth)); transform.position = wantedPos; } // ------------------------------- // FOLLOW MOUSE POSITION END // ------------------------------- function Update () { FollowMousePosition(); }
4. Inspector> Setup the Partycle System to create a fairy dust effect:
Particle System
– Start Size: 0.3
– Gravity Multiplier: 1
– Simulation Space: World -> really important!!!
Emission: check it
– Rate: 30
Shape: check it
– Shape: Sphere
– Radius 0.1
Limit Velocity over Lifetime: check it
– Speed: 3
– Dampen: 1