I have two problems that I’m not sure about why they’re not working.
First, which I just implemented another a different way because I couldn’t get it to work, was that when I accessed the Light component of a child game object, I was unable to enable or disable it. However, I was able to enable and disable the light when I set the light in the inspector.
Second, when I try to compare two game objects and I know they’re the same, it never evaluates them to be the same. I’ve tried == by game objects, ReferenceEquals, == by instance ID, and none have worked.
Working function that turns off lights using inspector.
private void TurnOffAllButtonLights()
{
for (int i = 0; i < buttonLights.Length; i++)
{
buttonLights*.enabled = false;*
}
}
Non-working function to turn off lights. GetPlayButtons() returns the list of play buttons from a different script.
private void TurnOffAllButtonLights()
{
for (int i = 0; i < buttonSystem.GetPlayButtons().Length; i++)
{
buttonSystem.GetPlayButtons().GetComponentInChildren().enabled = false;
}
}
----------
Function that gets player input and checks if they clicked one of the play buttons.
private void ProcessPlayerInput()
{
bool isGameButton = false;
GameObject[] playButtons = buttonSystem.GetPlayButtons();
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
bool hasHit = Physics.Raycast(ray, out hit);
for (int i = 0; i < playButtons.Length; i++)
{
if (playButtons*.gameObject == hit.transform.gameObject)*
{
Debug.Log(“Is Game Button”);
isGameButton = true;
}
}
if (hasHit && isGameButton)
{
Debug.Log(hit.transform.gameObject.name);
}
}
I’ve printed out the name of the game object and it says they’re the same, but they’re still not evaluated to be the same. Is it because it’s referencing it from another script? Or something else I’m missing?
I’d appreciate any help.