- Home /
Problem with blinking!!! Argh
Help!! Argh i'm doing the Walker Boys Lab (mega-nice tutorials by the way, Kudos, to them for that!) But I'm doing the the first lab! And the sphere blinking is driving me crazy!!!
Here is the problem : I'm starting the routine and I got a swicht that toggle on and off depending if it's need to blink or not. But the problem is that this swicth whenever i put it its never swicth back to false! Hope you can help me!
Here is the code :
//Enemy Script</p> <pre><code>//Inspector Variables var shapeColor:Color[]; var numberOfClick:int = 1; var explosion : Transform; var enemyPoint:int = 1; var respawnTime:float; var BlinkToggle:boolean=false; //private Variables private var storeClicks:int = 0; private var rotateSpeed:int=50; function Start() { respawnTime = Random.Range(1.0, 5.0); storeClicks = numberOfClick; var startPosition = Vector3(Random.Range(-6,6), Random.Range(4,-4), 0); transform.position = startPosition; RandomColor(); } function Update () { RotateMe(); if(numberOfClick <= 0) { BlinkingCoroutine(); if(BlinkToggle==true) { BlinkToggle=false; if(explosion) { Instantiate(explosion, transform.position, transform.rotation); } if(audio.clip) { audio.Play(); } var position = Vector3(Random.Range(-6,6), Random.Range(4,-4), 0); RespawnWaitTime(); transform.position = position; numberOfClick = storeClicks; } } } //Change the respawn time function RespawnWaitTime() { renderer.enabled = false; RandomColor(); yield WaitForSeconds(respawnTime); renderer.enabled = true; } //Change the color of Mat when respawning function RandomColor() { if(shapeColor.length > 0) { var newColor = Random.Range(0, shapeColor.length); renderer.material.color = shapeColor[newColor]; } else { print("You've have to set the color array in the inspector"); } } function RotateMe() { transform.RotateAround(Vector3.zero, Vector3(0,0,1), rotateSpeed * Time.deltaTime); } function Blinking() //Do the blinking by turning it on and off; { renderer.enabled = !renderer.enabled; } function EvokeBlinking() //Evoke the Blinking Command each 0.3 sec for 1 sec. { InvokeRepeating("Blinking", 1, .3); } function BlinkingCoroutine() //Start the calling of the coroutine. Call the blinking for 3 sec, then cancel the invoke and turn back the renderer. { EvokeBlinking(); yield WaitForSeconds(3); CancelInvoke("Blinking"); renderer.enabled=true; BlinkToggle=true; }
If you put this on an object in an empty scene, it rotates. If you set the number of clicks variable to a negative number it blinks. BlinkToggle doesn't seem to have any effect on that. It does have an effect on the actual blink code. What is number of clicks used for in the script?
Just one click before it got destroy! That what bugger me! The sphere is rotating and if you click on it I got a raycast function in the player script that kill the sphere and the blinking should happen!