Advertisement
polyfied

Particle Playground - Switch world object

Nov 8th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using ParticlePlayground;
  4.  
  5. public class SwitchWorldObject : MonoBehaviour {
  6.  
  7.     public PlaygroundParticlesC particles;      // Reference to your particle system
  8.     public GameObject[] worldObjects;           // Assign your world objects (needs a mesh)
  9.  
  10.     int current;
  11.  
  12.     void Update () {
  13.         if (Input.GetMouseButtonDown (0)) {
  14.             StartCoroutine(Switch());
  15.         }
  16.     }
  17.  
  18.     IEnumerator Switch () {
  19.         if (worldObjects.Length==0) yield break;
  20.         current = (current+1)%worldObjects.Length;
  21.  
  22.         // Update the current computed world object
  23.         particles.worldObject.gameObject = worldObjects[current];
  24.  
  25.         // The new world object will be available next frame
  26.         yield return null;
  27.  
  28.         // Set particle count to match the vertex amount
  29.         particles.particleCount = particles.worldObject.vertexPositions.Length;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement