- Home /
Disable Game object, Enable other Game objects after 5 seconds to show progress
Hi I want to disable game object and enable other object and do this for all object in 5 second for each one to show progress, i did this by adding a script to ImageTarget with this code:
public class cv : MonoBehaviour
{
void Start()
{
StartCoroutine(LateCall());
}
IEnumerator LateCall()
{
Obj1.SetActive(true);
yield return new WaitForSeconds(5f);
Obj1.SetActive(false);
Obj2.SetActive(true);
yield return new WaitForSeconds(5f);
Obj2.SetActive(false);
Obj3.SetActive(true);
yield return new WaitForSeconds(5f);
Obj3.SetActive(false);
Obj4.SetActive(true);
yield return new WaitForSeconds(5f);
Obj4.SetActive(false);
Obj5.SetActive(true);
yield return new WaitForSeconds(5f);
Obj5.SetActive(false);
Obj6.SetActive(true);
yield return new WaitForSeconds(5f);
Obj6.SetActive(false);
Obj7.SetActive(true);
yield return new WaitForSeconds(5f);
Obj7.SetActive(false);
Obj8.SetActive(true);
yield return new WaitForSeconds(5f);
Obj8.SetActive(false);
Obj9.SetActive(true);
yield return new WaitForSeconds(5f);
Obj9.SetActive(false);
Obj10.SetActive(true);
yield return new WaitForSeconds(5f);
Obj10.SetActive(false);
Obj11.SetActive(true);
yield return new WaitForSeconds(5f);
Obj11.SetActive(false);
Obj12.SetActive(true);
}
[SerializeField] private GameObject Obj1;
[SerializeField] private GameObject Obj2;
[SerializeField] private GameObject Obj3;
[SerializeField] private GameObject Obj4;
[SerializeField] private GameObject Obj5;
[SerializeField] private GameObject Obj6;
[SerializeField] private GameObject Obj7;
[SerializeField] private GameObject Obj8;
[SerializeField] private GameObject Obj9;
[SerializeField] private GameObject Obj10;
[SerializeField] private GameObject Obj11;
[SerializeField] private GameObject Obj12;
}
What is the problem?
First of all, this is not how you should be handling any of this. Something more like this...
IEnumerator LateCall()
{
for (int i = 0; i < objectArray.Length; i++)
{
objectArray[i].SetActive(true);
yield return new WaitForSeconds(5f);
objectArray[i].SetActive(false);
}
}
public GameObject[] objectArray;
what outcome are you looking to get? have you tried to do : {Edit to use @RobAnthem 's method}
bool check;
public GameObject[] objectArray;
IEnumerator $$anonymous$$yEnumerator(){
for (int i = 0; i < objectArray.Length; i++)
{
check=Equals( objectArray[i].enabled, true);
objectArray[i].SetActive(true);
while (Equals(check,true)){
yield return WaitForSeccond(5.0f);
objectArray[i+1].SetActive(true);
}
yield return new WaitForSeconds(5f);
objectArray[i-1].SetActive(false);
}
Answer by SharkoFR · Feb 16, 2019 at 03:36 PM
First of all, try to put the GameObject variables before the IEnumerator (i suggest you to place it at the top (before the start). Then are you sure your GameObjects are assigned? and Do you get any errors?
Thanks, i didnt get any error and i assigned all objects
Answer by Uios-Theou · Feb 17, 2019 at 02:50 PM
There has got to be an easier way than this.
That code is hard to look at.
Have you tried using a list, maybe a queue, to achieve your goal?
Add the objects to a list. Start a Coroutine like,
IEnumerator FlashObjects
{
I = 0;
while(I < list.count)
{
list[I].setActive(true);
if(I - 1 >= 0 && I - 1 <= list.count)
{
list[I-1].setactive(false);
}
I++;
yield return new wait for seconds (5);
}
}
This should work and looks a lot nicer and cleaner , in my humble opinion, but im a rookie coder.
Your answer

Follow this Question
Related Questions
Vuforia Database Load Behavior 1 Answer
How to make object showing depend on target? 1 Answer
Cloud recognition in Vuforia 0 Answers
Vuforia tracks without showing objects 0 Answers
AR Camera zoomed in on iPad Air 2 0 Answers