1 using UnityEngine;
2 using
System.Collections;
3
4 public
class DetonatorSprayHelper : MonoBehaviour {
5 public
float startTimeMin = 0;
6 public
float startTimeMax = 0;
7 public
float stopTimeMin = 10;
8 public
float stopTimeMax = 10;
9
10 public
Material firstMaterial;
11 public
Material secondMaterial;
12
13 private
float startTime;
14 private
float stopTime;
15
16 //the time at which
this came into existence
17 private
bool isReallyOn;
18
19 void
Start (){
20     isReallyOn = GetComponent<ParticleEmitter>().emit;
21     
22     
//this kind of emitter should always start off
23     GetComponent<ParticleEmitter>().emit =
false;
24     
25     
//get a random number between startTimeMin and Max
26     startTime = (Random.
value * (startTimeMax - startTimeMin)) + startTimeMin + Time.time;
27     stopTime = (Random.
value * (stopTimeMax - stopTimeMin)) + stopTimeMin + Time.time;
28     
29     
//assign a random material
30     GetComponent<Renderer>().material = Random.
value > 0.5f ? firstMaterial : secondMaterial;
31 }

32
33 void
FixedUpdate (){
34     
//is the start time passed? turn emit on
35     
if (Time.time > startTime)
36     {
37         GetComponent<ParticleEmitter>().emit = isReallyOn;
38     }
39     
40     
if (Time.time > stopTime)
41     {
42         GetComponent<ParticleEmitter>().emit =
false;
43     }
44 }
45 }