- Home /
Question by
Pathojen · Aug 26, 2020 at 04:13 PM ·
2drandom.rangeienumeratorsetactive
Toggle 2D Object Active?
How do I toggle an object on and off? I have a 2D object That is supposed to toggle after a short, random amount of time, but nothing I try sets it to false. Here's the quick code that I have so far.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EyesScript : MonoBehaviour
{
public GameObject Eyes;
public float RandomNo;
// Start is called before the first frame update
void Start()
{
RandomNo = Random.Range(1f, 5f);
}
IEnumerator Blink()
{
yield return new WaitForSeconds(RandomNo);
RandomNo = Random.Range(1f, 10f);
Eyes.SetActive(!Eyes.activeInHierarchy);
}
}
Comment
Your answer
Follow this Question
Related Questions
How to randomize the order of objects? 5 Answers
Instantiate GameObject at Random time is not working 1 Answer
Scipt Not Functioning Properly 1 Answer
physics.OverlapSphere colliders 1 Answer