- Home /
C# Turn Off / Null A Method
I've written a script that calls for a method and starts it how ever I want to be able to stop / null it after a certain condition for explain:
void Update() { if (Input.GetMouseButtonDown(0)) { // Stop Blink method } }
void Start()
{
StartCoroutine(Blink());
}
IEnumerator Blink()
{
yield return new WaitForSeconds(0.5F);
while (blinkTime > 0)
{
blinkTime--;
yield return new WaitForSeconds(0.5F);
renderer.enabled = false;
yield return new WaitForSeconds(0.5F);
renderer.enabled = true;
}
yield return new WaitForSeconds(0.5F);
renderer.enabled = false;
}
Comment
Best Answer
Answer by ScroodgeM · Aug 05, 2012 at 11:43 AM
replace
// Stop Blink methodwith
blinkTime = 0;
...or, if you want not to zero this variable, add another one of type boolean, check it and blink only if it is true, and set in to true on start and to false when you want to stop blinking
Your answer

Follow this Question
Related Questions
Method returning null, when referenced from another script 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
On Spawn Method 0 Answers
Setting Prefab with Code Returns NULL 2 Answers