Why does this not make my object repetitively go on and off
This is my code
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Delay : MonoBehaviour {
public GameObject laserBeam;
private float timeWait;
private bool setActiveBool;
void Start () {
StartCoroutine (DelayScript ());
}
IEnumerator DelayScript () {
while (true) {
timeWait = 0.2f;
yield return new WaitForSeconds(timeWait);
if (setActiveBool) {;
laserBeam.SetActive (true);
setActiveBool = false;
}
if (!setActiveBool) {
laserBeam.SetActive (true);
setActiveBool = true;
}
}
}
}
Comment
Best Answer
Answer by Hellium · May 29, 2017 at 10:04 AM
Because you have an extra semi-colon here :
if (setActiveBool) {;
By the way, you never pass "false" to your laserBeamSetActive
function
I have done both of these things yet the object is still there permanently.
Try to add an "else" before the second condition :
else if (!setActiveBool) {
Your answer
