buttonArray is looking all the buttons

hi, i´m have a problem with the this code:

, i have this error, and dont knoe why.

Hi,

This line of code within the Start method of your ButtonScript;

buttonArray = GameObject.FindObjectsOfType<Button>();

You appear to have changed the names of the scripts from that in the lecture(s), what the above is doing is finding all of the GameObjects which have a Button script attached. As you can see from your second screenshot, the WinButton has a Button script attached.

The only buttons you are actually interested in are the ones at the top for selecting defenders, I can’t remember for certain, but I thought the WinButton and LoseButton had been removed from the scene by this point?

Your script ButtonScript would be ideally renamed to Button or, change the name of what you are trying to find in the line of code above, e.g.

buttonArray = GameObject.FindObjectsOfType<ButtonScript>();

Also, it is typically better to copy/paste your code into your posts on the forum and then apply the code formatting characters both before and after it. This allows those who help you to copy/paste parts of your code back for you, rather than having to type it all out from a screenshot.

Screenshots are however really useful when it comes to errors messages or details within the Unity editor itself.

Hope this helps :slight_smile:


See also;

thank you so much Rob, i`m about to freaking out.

1 Like

You’re very welcome Marcio. :slight_smile:

Privacy & Terms