Hi, newbie here. My aim is to turn the color of each created object first to white then to black. My problem is that I couldn’t figure out how to assign and / or check the bool for each created object. It’s my code here :`
public class GameManager : MonoBehaviour
{
[SerializeField]
GameObject ballPreF;
[SerializeField]
Transform ballPanel;
//bool checkPBall = true;
GameObject[] ballsArray = new GameObject[10]; //This number is increasing
GameObject selectedBall;
void Start()
{
BallCreator();
}
public void BallCreator()
{
for (int i = 0; i < 10; i++)
{
GameObject ball = Instantiate(ballPreF, ballPanel);
ball.transform.GetComponent<Button>().onClick.AddListener(() => ClickedB());
ballsArray *= ball;*
}
}
void ClickedB()
{
selectedBall = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject;
-
bool checkPBall = true;*
if (checkPBall == true)
{
selectedBall.transform.GetComponent().color = new Color(255, 255, 255);
checkPBall = false;
//Debug.Log(checkPBall);
}
else if (checkPBall == false) //not working i don’t know why??
{
selectedBall.transform.GetComponent().color = new Color(0, 0, 0);
selectedBall.transform.GetComponent().interactable = false;
//Debug.Log(checkPBall);
return;
}
Debug.Log(checkPBall); //return false
//UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.transform.GetComponent().color = new Color(255, 255, 255);
}
}
`