Hello. Everyone here has been so helpful so far, but it appears I am stuck once more. How would I write code that is essentially:
'For each child of public GameObject ‘Deck’, that is also of the class ‘CardDisplay’ return the name and save it to public Array ‘Deck1’.
I, of course, wouldn’t ask without trying first so here is my completely non working attempt:
using UnityEngine;
using UnityEngine.UI;
//using System;
public class DeckLoader : MonoBehaviour
{
public Text deckName;
public GameObject DeckLeader;
public string[] Deck1;
public Text Leader;
public GameObject deck;
public void CreateDeck()
{
Leader.text = DeckLeader.name;
//Find anything with the class CardDisplay. Why is there the array [] symbol???
CardDisplay[] deck = GetComponentsInChildren<CardDisplay>();
foreach (CardDisplay child in deck)
{
//'this' seems to reference this GameObject and no the children
string Name = this.name;
int i = 0;
Deck1 = Name;
i++;
}
}
}
The error I am getting is:
IndexOutOfRangeException: Index was outside the bounds of the array.
(wrapper stelemref) System.Object.virt_stelemref_sealed_class(intptr,object)