Exemplo n.º 1
0
    void Update()
    {
        if (Input.GetKey(KeyCode.S))
        {
            compressor.Disable();
            GameObject newLiquidParticle = (GameObject)Instantiate(Resources.Load(ResourceDirectories.DynamicParticle)); //Spawn a particle
            newLiquidParticle.GetComponent <Rigidbody2D>().AddForce(particleForce);                                      //Add our custom force
            DynamicParticle particleScript = newLiquidParticle.GetComponent <DynamicParticle>();                         // Get the particle script
            particleScript.SetState(particlesState);                                                                     //Set the particle State
            newLiquidParticle.transform.position = transform.position;                                                   // Relocate to the spawner position
            newLiquidParticle.transform.parent   = particlesParent;                                                      // Add the particle to the parent container
        }

        //Old method by setting number of particles

        /*
         * if (lastSpawnTime + SPAWN_INTERVAL < Time.time && numberOfParticles > 0)
         * { // Is it time already for spawning a new particle?
         *  GameObject newLiquidParticle = (GameObject)Instantiate(Resources.Load(ResourceDirectories.DynamicParticle)); //Spawn a particle
         *  newLiquidParticle.GetComponent<Rigidbody2D>().AddForce(particleForce); //Add our custom force
         *  DynamicParticle particleScript = newLiquidParticle.GetComponent<DynamicParticle>(); // Get the particle script
         *  particleScript.SetState(particlesState); //Set the particle State
         *  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
         *  --numberOfParticles;
         * }
         * else if(numberOfParticles <= 0)
         * {
         *  gameObject.SetActive(false);
         * }
         */
    }
Exemplo n.º 2
0
 void Update()
 {
     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
         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
     }
 }
Exemplo n.º 3
0
 private void Update()
 {
     if (lastSpawnTime + SPAWN_INTERVAL < Time.time)
     {                                                                            // Is it time already for spawning a new particle?
         DynamicParticle particleScript = Instantiate(prefab);                    // Get the particle script
         particleScript.rigidBodyDynamic.AddForce(particleForce);                 //Add our custom force
         particleScript.SetLifeTime(PARTICLE_LIFETIME);                           //Set each particle lifetime
         particleScript.SetState(particlesState);                                 //Set the particle State
         particleScript.rigidBodyDynamic.transform.position = transform.position; // Relocate to the spawner position
         particleScript.rigidBodyDynamic.transform.parent   = particlesParent;    // Add the particle to the parent container
         lastSpawnTime = Time.time;                                               // Register the last spawnTime
     }
 }
Exemplo n.º 4
0
 void Start()
 {
     for (int i = 0; i < numInitial; i++)
     {
         GameObject newLiquidParticle = (GameObject)Instantiate(particle);                                                          //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
         newLiquidParticle.transform.localScale = new Vector3(1 * transform.localScale.x, 1 * transform.localScale.y, 1 * transform.localScale.z);
         newLiquidParticle.transform.position   = transform.position + (particlesEnd.position - transform.position) * Random.value; // Relocate to the spawner position
         newLiquidParticle.transform.parent     = particlesParent;                                                                  // Add the particle to the parent container
         lastSpawnTime = Time.time;                                                                                                 // Register the last spawnTime
     }
 }
Exemplo n.º 5
0
    IEnumerator SpawnWater()
    {
        while (amount < WaterToSpawn)
        {
            amount++;
            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
            newLiquidParticle.transform.position = new Vector2(Random.Range(transform.position.x - 0.1f, transform.position.x + 0.1f), transform.position.y); // Relocate to the spawner position
            newLiquidParticle.transform.parent   = particlesParent;                                                                                           // Add the particle to the parent container

            yield return(new WaitForSeconds(SPAWN_INTERVAL));
        }
    }
Exemplo n.º 6
0
 void spawnParticles(int rotationModifier, int baseNumberToSpawn)
 {
     //COME BACK HERE
     if (lastSpawnTime + SPAWN_INTERVAL < Time.time && particlesSpawned < 300 && pouringManager.isPouring == true) //&& gameObject.transform.rotation.eulerAngles.z > somePredefinedSize)
     {                                                                                                             // Is it time already for spawning a new particle?
         GameObject newLiquidParticle = (GameObject)Instantiate(Resources.Load("LiquidPhysics/DynamicParticle"));  //Spawn a particle
         particlesSpawned += 1;
         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
         newLiquidParticle.transform.position = spawner.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
     }
 }
Exemplo n.º 7
0
 public DynamicParticle Spawn()
 {
     if (lastSpawnTime + SpawnInterval < Time.time)
     {                                                                                        // Is it time already for spawning a new particle?
         var newLiquidParticle = Instantiate(LiquidParticlePrefab);                           //Spawn a particle
         newLiquidParticle.GetComponent <Rigidbody2D>().AddForce(particleForce);              //Add our custom force
         DynamicParticle particleScript = newLiquidParticle.GetComponent <DynamicParticle>(); // Get the particle script
         particleScript.SetLifeTime(ParticleLifetime, ParticleScaleDelay);                    //Set each particle lifetime
         particleScript.SetState(particlesState);                                             //Set the particle State
         particleScript.SetRadius(InitialRadius);
         newLiquidParticle.transform.position = StartPosition.position;                       // Relocate to the spawner position
         newLiquidParticle.transform.parent   = particlesParent;                              // Add the particle to the parent container
         lastSpawnTime = Time.time;                                                           // Register the last spawnTime
         return(particleScript);
     }
     return(null);
 }
 void Update()
 {
     if (lastSpawnTime + SPAWN_INTERVAL < Time.time && numberOfParticles > 0)
     {                                                                                                                 // Is it time already for spawning a new particle?
         GameObject newLiquidParticle = (GameObject)Instantiate(Resources.Load(ResourceDirectories.DynamicParticle2)); //Spawn a particle
         newLiquidParticle.GetComponent <Rigidbody2D>().AddForce(particleForce);                                       //Add our custom force
         DynamicParticle particleScript = newLiquidParticle.GetComponent <DynamicParticle>();                          // Get the particle script
         particleScript.SetState(particlesState);                                                                      //Set the particle State
         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
         --numberOfParticles;
     }
     else if (numberOfParticles <= 0)
     {
         gameObject.SetActive(false);
     }
 }