Question by
Ignorable_Lettuce · Aug 01, 2020 at 12:29 AM ·
scripting problemui imagestartcoroutine
Coroutine wont start
I'm trying to get an image to show up every so often, using a canvas, and I think it's because the coroutine won't start. can someone look at my script?
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class JumpScare : MonoBehaviour {
private IEnumerator Example;
private Image Image;
public void Awake()
{
}
// Start is called before the first frame update
void Start()
{
Image = GetComponent<Image>();
gameObject.SetActive(false);
StartCoroutine(Example);
}
// Update is called once per frame
void Update()
{
IEnumerator Example()
{
int wait_time = Random.Range(1, 5);
yield return new WaitForSeconds(wait_time);
gameObject.SetActive(true);
int wait_time2 = Random.Range(2, 1);
yield return new WaitForSeconds(wait_time2);
gameObject.SetActive(false);
if (Input.GetKeyDown("i"))
{
Image.enabled = Image.enabled;
int wait_time3 = Random.Range(2, 1);
Image.enabled = !Image.enabled;
gameObject.GetComponent<Renderer>().enabled = false;
}
}
}
}
Any help would be greatly apreciated, thank you.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613004605im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Trigger GUI elements 1 Answer
UnityEngine.UI and UnityEngine.EventSystem do not work, what do I do? 1 Answer
Using downloaded image as UI Image's source image? 1 Answer
Some scripts seem to be breaking when re-loading a scene 0 Answers
why the startcoroutine (spawnbigtree()); doesn't work and float don't work 0 Answers