Advertisement
mysterious_3D

ParticleSystem

Oct 4th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. private var litAmount = 1.00;
  3.  
  4. function Start () {
  5.  
  6.     var playerController : ThirdPersonController = GetComponent(ThirdPersonController);
  7.    
  8.     // The script ensures an AudioSource component is always attached.
  9.    
  10.     // First, we make sure the AudioSource component is initialized correctly:
  11.     GetComponent.<AudioSource>().loop = false;
  12.     GetComponent.<AudioSource>().Stop();
  13.    
  14.    
  15.     // Init the particles to not emit and switch off the spotlights:
  16.     var particles : Component[] = GetComponentsInChildren(ParticleEmitter);
  17.     var childLight : Light = GetComponentInChildren(Light);
  18.    
  19.     for (var p : ParticleEmitter in particles)
  20.     {
  21.         p.emit = true;
  22.     }
  23.     childLight.enabled = false;
  24.  
  25.     // Once every frame  update particle emission and lights
  26.     while (true)
  27.     {
  28.         var isFlying = playerController.IsJumping();
  29.                
  30.         // handle thruster sound effect
  31.         if (isFlying)
  32.         {
  33.             if (!GetComponent.<AudioSource>().isPlaying)
  34.             {
  35.                 GetComponent.<AudioSource>().Play();
  36.             }
  37.         }
  38.         else
  39.         {
  40.             GetComponent.<AudioSource>().Stop();
  41.         }
  42.        
  43.        
  44.         for (var p : ParticleEmitter in particles)
  45.         {
  46.             p.emit = isFlying;
  47.         }
  48.        
  49.         if(isFlying)
  50.             litAmount = Mathf.Clamp01(litAmount + Time.deltaTime * 2);
  51.         else
  52.             litAmount = Mathf.Clamp01(litAmount - Time.deltaTime * 2);
  53.         childLight.enabled = isFlying;
  54.         childLight.intensity = litAmount;
  55.                    
  56.         yield;
  57.     }
  58. }
  59.  
  60. @script RequireComponent(AudioSource)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement