- Home /
Object continues cloning on instantiate
I a quick question with my script. It seems the object won't stop instantiating? I turned hitFrontCol on, which should stop it, but I does not seem to. How can I take the if statement out of the Update with it still checking for the boolean?
 var position : Vector3;
 var platform : GameObject;
 var speed = 0;
 var hitFrontCol : boolean = false;
 var hitBackCol : boolean = false;
 
 function  Update () {
     
            if (hitFrontCol) {
            
            hitBackCol = false;
            
      var platformClone = Instantiate(platform, position, Quaternion.identity);
      platformClone.velocity = transform.right * speed;
      
      }
      
      if (hitBackCol) {
      
      hitFrontCol = false;
      
      }
 
 }
 
 function hasHitFront ()  {
 
 hitFrontCol = true;
 
 }
 
 function hasHitBack () {
 
 hitBackCol = true;
 
 }
Answer by SinisterRainbow · Jul 12, 2013 at 08:26 AM
man.. you set hitBackCol = false, so it never enters you 2nd if statement, and so hitFrontCol never turns false. also, there's no reason i can see for the 2nd if statement. in the "if(hitFrontCol){..}" you should automatically set hitFrontCol=false; and not care about the state of hitBackCol
No, no. I set hitFrontCol to "true" in the inspector so it could instantiate once and turn off. The other two functions are called from another script. I need hitBackCol as a fail safe to turn off the hitFrontCol.
Oh! I am really sorry. I took your answer as incorrect the first time so when I discarded it and answered it myself, I forgot all about it. Sorry again, and thanks for the answer.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                