예제 #1
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
     }
 }
예제 #2
0
 void Update()
 {
     if (lastSpawnTime + SPAWN_INTERVAL < Time.time)                                                                              // Is it time already for spawning a new particle?
     {
         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.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
     }
 }
    IEnumerator SpawnNew()
    {
        GameObject newLiquidParticle = (GameObject)Instantiate(Resources.Load("WFX/WaterDrop")); //Spawn a particle prefab (located in the Resource folder)

        k++;                                                                                     // Indicate that a new waterdrop particle is added to the scene
        DynamicParticle particleScript = newLiquidParticle.GetComponent <DynamicParticle>();     // Get the script of the waterdrop particle

        particleScript.OR = carbody;                                                             // Refrence the rigidBody of the car to the script for the G-Force calculations
        particleScript.SetLifeTime(Random.Range(1f, PARTICLE_LIFETIME_MustBeMoreThanOne));       //Set each particle lifetime
        particleScript.Spawner = this;
        newLiquidParticle.transform.position = transform.position;                               // Relocate the waterdrop to the spawner position
        newLiquidParticle.transform.parent   = particlesParent;                                  // Add the particle to the parent container
        yield return(new WaitForSeconds(Random.Range(0.2f, 5f)));                                //We don't want to spawn all the waterdrops at once, we spawn them every 0.2 to 5 seconds to mimic the rain effect in real life.
    }
예제 #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
     }
 }
예제 #5
0
    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.CompareTag("Team1") && col.gameObject.GetComponent <CollectorScript>().water > 0)
        {
            sound.PlaySound("Throw");

            col.gameObject.GetComponent <CollectorScript>().water--;
            CountWater++;
            GameObject newLiquidParticle = (GameObject)Instantiate(Resources.Load("LiquidPhysics/DynamicParticle 1")); //Spawn a particle

            DynamicParticle particleScript = newLiquidParticle.GetComponent <DynamicParticle>();                       // Get the particle script
            particleScript.SetLifeTime(99999999999f);                                                                  //Set each particle lifetime
            newLiquidParticle.transform.position = new Vector2(spawn.position.x, spawn.position.y);                    // Relocate to the spawner position
            newLiquidParticle.transform.parent   = transform;
        }
    }
예제 #6
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));
        }
    }
예제 #7
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
     }
 }
    public Transform particlesParent;                                            // Where will the spawned particles will be parented (To avoid covering the whole inspector with them)

    void Start()
    {
        for (int i = 0; i < 70; i++)
        {
            //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.gameObject.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
            //}
        }
    }
예제 #9
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);
 }
예제 #10
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"),
                                                                    transform.position + particleStartPosition, Quaternion.identity); //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
         }
     }
 }