Hi,
I tried to create a script which toggles a GameObject (in this case an information text) on or off:
using UnityEngine;
using System.Collections;
public class toggleInformation : MonoBehaviour {
public GameObject ObjectToToggle;
public bool active;
void Start() {
active = true;
}
public void toggle() {
Debug.Log ("toggle");
if (active = true) {
ObjectToToggle.SetActive(false);
active = false;
} else if (active = false) {
ObjectToToggle.SetActive(true);
active = true;
} else {
Debug.Log ("Error: active neither true nor false");
}
}
}
Unfortunately it only works to toggle off the GameObject (default: it is turned on when starting the game).
Console shows only one “toggle” even though I pressed the button several times (button executes the script).
Any ideas? :-/
Thank you!