- Home /
 
Enable/Disable script with timer
hiya,
Do you have some time to help me on this, please? I have a particle system shooting at a sphere which I want to light up when particles collide.
Right now I have two scripts: 1 - one called "Color Change", that just swaps the sphere's material. 2 - and another called "Trigger" that is supposed to listen for particles that collide, enable "Color Change" during some time, and then disabling it.
I can't get it to disable the "Color Change" script. :/
1 - "Color Change" :
 var material1 : Material;
 var material2 : Material;
 
 
 function Update () {
 
     renderer.material.Lerp (material1, material2, 1);
      
  }
 
               2 - "Trigger" :
 private var startTime;
 
 private var restSeconds : int;
 
 private var roundedRestSeconds : int;
 
 private var displaySeconds : int;
 
 private var displayMinutes : int;
 
 
 
 var countDownSeconds : float;
 
 
 
 function Start () {
 
 
 
 GetComponent("Color Change").enabled = false;
 
 
 
 }
 
 
 
 
 
 function Awake() 
 
 {    
 
     Reset();
 
 }
 
 
 
 function Reset()
 
 {
 
     startTime = Time.time;
 
 }
 
 
 
 function OnParticleCollision (other : GameObject){
 
    
 
    Reset();
 
    GetComponent("Color Change").enabled = true;
 
    var guiTime = Time.time - startTime;
 
 
 
     restSeconds = countDownSeconds - (guiTime);
 
 
 
         if (restSeconds == 0) {
 
         print ("Time is Over");
 
         GetComponent("Color Change").enabled = false;
 
           }
 
           
 
      }
 
 
 
 
 
 function OnGUI () {
   
     //display the timer
 
     roundedRestSeconds = Mathf.CeilToInt(restSeconds);
 
     displaySeconds = roundedRestSeconds % 60;
 
     displayMinutes = roundedRestSeconds / 60; 
 
 
 
     text = String.Format ("{0:00}:{1:00}", displayMinutes, displaySeconds); 
 
     GUI.Label (Rect (400, 25, 100, 30), text);
 
 }
 
               p.s. should I make just one single script in which when the timer reaches 0, the material is just swapped back ? I don't want to use Mathf.Pingpong, because the sphere should just only light up once for every particle collided.
Thanks!
Answer by Alex Rider · Oct 07, 2012 at 01:46 AM
bump ?
Hi There.
Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. Answer fields are for answers only, as this is a knowledge base.
You can convert this answer to a comment (or just edit your original question), you'll also get a better chance of getting an actual answer if the main list shows none or one answer in blue =]
Your answer