I have been trying to solve this problem for many hours now, but i just cant figure it out.
I need to access the array "letters in the voids "nextItem" and "prevItem", but i get an error saying "ArgumentException: GetComponent requires that the requested component 'GameObject[]' derives from MonoBehaviour or Component or is an interface."
using UnityEngine;
using System.Collections;
public class buttons_abc : MonoBehaviour {
public int id;
public GameObject[] letters;
// Use this for initialization
void Start () {
id = 0;
GameObject[] letters = GameObject.FindGameObjectsWithTag ("letter");
letters[id].SetActive (true);
for (int i = 1; i < 32; i++) {
letters[i].SetActive (false);
}
}
public void nextItem(){
letters = GetComponent<GameObject[]>();
Debug.Log (id);
if(id < 32){
letters[id].SetActive (false);
letters[id + 1].SetActive (true);
id++;
} else {
Debug.Log("viimane t2ht");
}
}
public void prevItem(){
letters = GetComponent<GameObject[]>();
Debug.Log (id);
if(id > 0){
letters[id].SetActive(false);
letters[id-1].SetActive(true);
id--;
} else{
Debug.Log("esimene t2ht");
}
} }