Why isn't WaitForSeconds working?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class HideUnhideBtn : MonoBehaviour
{
public Button buttonToHide;
public float comeInTime = 32.5f;
IEnumerator Start()
{
buttonToHide.gameObject.SetActive(false);
yield return new WaitForSeconds(comeInTime);
buttonToHide.gameObject.SetActive(true);
}
}
I want to hide a button at start, and have it become active again but the WaitForSeconds isn't working...
Answer by xxmariofer · Aug 08, 2019 at 10:36 AM
Because probably the HinUnhidbtn script is attached to that exact button, and if the button is inactive the coroutine will never continue after the yield instruction, if you need to hide the objkect youcan make the button image transparent and srt interactable to false
Thank you so so much! I spent almost three hours of pulling my hair out to figure out what was wrong. You were right, I had the script attached to the button and all I had to do was attach it to an empty game object. Thanks!
Your answer
Follow this Question
Related Questions
Could not load source 'Coroutines.cs': No source available. 1 Answer
Whats wrong with this simple code? 1 Answer
2D platformer IEnumerator problems 1 Answer
Help in changing the GUI looks! 0 Answers
Using StartCoroutine in a Nested Class 0 Answers