Hi.
I attached one script to two Buttons. so I want GetComponent All Buttons with below script. but it give me below error.how can fix it?
public Button[] btn;
void Awake()
{
for (int i = 0; i <= btn.Length - 1; i++)
{
btn _= GetComponent<Button*> ();*_
* }*
* }*
Error is: error CS1525: Unexpected symbol `)’
Thanks.
the culprit is this part:
GetComponent<Button*> ()*
You cannot put index in the GetComponent command. If you need all the buttons then simply write:
GetComponents()
Focus on the plural part of the command. And you also don’t need it in a for loop. What you need to do is:
btn = GetComponents();
It will get all ‘Button’ components attached with the same gameobject with which the script is attached.