// Here we handle the collision events with another particles, in this example water+lava= water-> gas
 void OnCollisionEnter2D(Collision2D other)
 {
     if (currentState == STATES.WATER && other.gameObject.tag == "DynamicParticle")
     {
         DynamicParticle otherParticle = other.collider.GetComponent <DynamicParticle>();
         if (!particleColor.Equals(otherParticle.particleColor))
         {
             Color newColor = CombineColors(particleColor, other.collider.GetComponent <DynamicParticle>().particleColor);
             SetColor(newColor);
             otherParticle.SetColor(newColor);
         }
         if (otherParticle.currentState == STATES.LAVA)
         {
             SetState(STATES.GAS);
         }
     }
 }
Beispiel #2
0
 void Update()
 {
     if (emit)
     {
         if (lastSpawnTime + SPAWN_INTERVAL < Time.time)
         {                                                                                                            // Is it time already for spawning a new particle?
             GameObject newLiquidParticle = (GameObject)Instantiate(Resources.Load("LiquidPhysics/DynamicParticle")); //Spawn a particle
             newLiquidParticle.GetComponent <Rigidbody2D>().AddForce(particleForce);                                  //Add our custom force
             DynamicParticle particleScript = newLiquidParticle.GetComponent <DynamicParticle>();                     // Get the particle script
             particleScript.SetLifeTime(PARTICLE_LIFETIME);                                                           //Set each particle lifetime
             particleScript.SetState(particlesState);                                                                 //Set the particle State
             particleScript.SetColor(color);                                                                          //Set the particle Color
             newLiquidParticle.transform.position = transform.position;                                               // Relocate to the spawner position
             newLiquidParticle.transform.parent   = particlesParent;                                                  // Add the particle to the parent container
             lastSpawnTime = Time.time;                                                                               // Register the last spawnTime
         }
     }
 }