Unity3D – OnMouseDown – Set Color-Speed-Size-Gravity – Shuriken Particle System – Javascript

Unity’s Shuriken Particle System is easy to drive via code!

Create a scene with:

– Particle System

– Cube, attach the script:


#pragma strict

var myParticles : GameObject; // Assign in Inspector

function Start () {
} // END Start

function Update () {	
}// END Update

function OnMouseDown ()
{
        // When you click over the object
        Debug.Log('Particle Activaction!');
        myParticles.particleSystem.startColor = Color.red; // change Start Color
        myParticles.particleSystem.startSpeed = 30;        // change Start Speed
        myParticles.particleSystem.startSize = 30;         // change Start Size
        myParticles.particleSystem.gravityModifier = 1;    // use gravity
       
  
}// END OnMouseDown()

Inspector> DRAG AND DROP your Particle System over var myParticles

Play and click over the Cube.