Advertisement
AndrewRosyaev

Flame

Feb 7th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Flame : MonoBehaviour
  5. {
  6.     public bool WithParent;
  7.     public Transform FlameCell;
  8.     public float FlameRate;
  9.     public Vector2 Speed;
  10.     public Vector2 Size;
  11.     float timer;
  12.     public Vector2 lifetime;
  13.     public Vector3 ellipsoid;
  14.     public Gradient colors;
  15.     public bool AnimCell;
  16.  
  17.     //void
  18.  
  19.     void Update ()
  20.     {
  21.         timer += Time.deltaTime;
  22.         if (timer > FlameRate)
  23.         {
  24.             Transform tr = Instantiate (FlameCell, transform.position + new Vector3 (Random.Range (ellipsoid.x, -ellipsoid.x), Random.Range (ellipsoid.y, -ellipsoid.y), Random.Range (ellipsoid.z, -ellipsoid.z)), transform.rotation) as Transform;
  25.             if (WithParent)
  26.             {
  27.                 tr.parent = transform;
  28.             }
  29.  
  30.             if (!AnimCell) {
  31.                 tr.GetComponent<FlameCell> ().speed = Random.Range (Speed.x, Speed.y);
  32.                 tr.GetComponent<FlameCell> ().grad = colors;
  33.                 float rndScale = Random.Range (Size.x, Size.y);
  34.                 tr.localScale = new Vector3 (rndScale, rndScale, rndScale);
  35.                 tr.GetComponent<FlameCell> ().LifeTime = Random.Range (lifetime.x, lifetime.y);
  36.             } else
  37.             {
  38.                 tr.GetComponent<FlameCellAnim> ().Lifetime = Random.Range (lifetime.x, lifetime.y);
  39.             }
  40.             timer = 0;
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement