Steps to Complete:
1. I created 5 sphere game objects.
2. I created a logic script that handles the gameobjects and logic. All 5 balls were added to the a gameObj array.
3. I created a coroutine that is called. It waits for a second before increasing the index in the array. When the index is called later on, I used (index % 5) so that the it is always calls an object within the scope of the array. The index is called to set the new size of the spheres. The coroutine recursively calls itself so that the program enters and infinitive loop.
4. I created a function that gets called when the "hide" button gets pressed. When called, this function hides or shows the unselected balls based on the value stored in the bool "active".
5. I added materials to each of the balls for a pop of color.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ObjSelectionLogic : MonoBehaviour
{
public GameObject[] objArr = new GameObject[5];
int selectedIndex = 0;
public float bigSize = 1.5f;
public float smallSize = 1f;
public Button activeBalls;
bool active = true;
{
public GameObject[] objArr = new GameObject[5];
int selectedIndex = 0;
public float bigSize = 1.5f;
public float smallSize = 1f;
public Button activeBalls;
bool active = true;
// Start is called before the first frame update
void Start()
{
activeBalls.onClick.AddListener(hide);
objArr[selectedIndex].transform.localScale = new Vector3(bigSize, bigSize, bigSize);
StartCoroutine(selectionObjWaiter());
void Start()
{
activeBalls.onClick.AddListener(hide);
objArr[selectedIndex].transform.localScale = new Vector3(bigSize, bigSize, bigSize);
StartCoroutine(selectionObjWaiter());
}
IEnumerator selectionObjWaiter()
{
//given big ball active : wait and set small and inactive
yield return new WaitForSeconds(1);
if (!active)
{
objArr[selectedIndex%5].SetActive(false);
}
objArr[selectedIndex%5].transform.localScale = new Vector3(smallSize, smallSize, smallSize);
selectedIndex++;
{
//given big ball active : wait and set small and inactive
yield return new WaitForSeconds(1);
if (!active)
{
objArr[selectedIndex%5].SetActive(false);
}
objArr[selectedIndex%5].transform.localScale = new Vector3(smallSize, smallSize, smallSize);
selectedIndex++;
//given time waited, object small and inactive, selected index increased: set new ball active and big
//if (!active)
//{
// objArr[selectedIndex].SetActive(true);
//}
objArr[selectedIndex%5].SetActive(true);
objArr[selectedIndex%5].transform.localScale = new Vector3(bigSize, bigSize, bigSize);
StartCoroutine(selectionObjWaiter());
}
void hide()
{
if (active == true){
active = false;
foreach(GameObject ball in objArr)
{
ball.SetActive(false);
objArr[selectedIndex % 5].SetActive(true);
}
}
else
{
active = true;
foreach(GameObject ball in objArr)
{
ball.SetActive(true);
}
}
}
}
//if (!active)
//{
// objArr[selectedIndex].SetActive(true);
//}
objArr[selectedIndex%5].SetActive(true);
objArr[selectedIndex%5].transform.localScale = new Vector3(bigSize, bigSize, bigSize);
StartCoroutine(selectionObjWaiter());
}
void hide()
{
if (active == true){
active = false;
foreach(GameObject ball in objArr)
{
ball.SetActive(false);
objArr[selectedIndex % 5].SetActive(true);
}
}
else
{
active = true;
foreach(GameObject ball in objArr)
{
ball.SetActive(true);
}
}
}
}