Hi Im trying to make an Instance of a prefab and the edit some components in the children but i can’t seam to be able to use the GetComponent function. This is the code where the error happens:
public void Create()
{
for(int A = 0; A != Druk_A_C.Length; A++)
{
GameObject Temp = Instantiate(Template_List, Container.transform);
Temp.transform.Find("Name").gameObject.GetComponent<Text>().text = Druk_A_C[A].GetName();
}
}
And there is all the code if you need:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;
public class Master : MonoBehaviour {
public TextAsset Drunk;
private A_C[] Druk_A_C;
private string[] Drinks;
private string[] split;
public GameObject Template_List;
public GameObject Container;
void Awake()
{
string temp_druk = Drunk.text;
Drinks = temp_druk.Split('
');
Drinks[0] = “”;
split = null;
Druk_A_C = new A_C[Drinks.Length];
Load_1();
Create();
}
//loading
public void Load_1()
{
List<string> Splitter = new List<string>();
for (int iso = 1; iso < Drinks.Length; iso++)
{
Splitter = new List<string>();
string[] Temp = this.Drinks[iso].Split(' ');
for (int num = 0; num < Temp.Length; num++)
{
Splitter.Add(Temp[num]);
}
split = Splitter.ToArray();
Druk_A_C[iso] = new A_C();
Druk_A_C[iso].SetName(split[0]);
Druk_A_C[iso].SetIGD(split[1]);
Druk_A_C[iso].SetType(split[2]);
Druk_A_C[iso].SetText(split[3]);
}
}
public void Create()
{
for(int A = 0; A != Druk_A_C.Length; A++)
{
GameObject Temp = Instantiate(Template_List, Container.transform);
Temp.transform.Find("Name").gameObject.GetComponent<Text>().text = Druk_A_C[A].GetName();
}
}
}
class A_C
{
private string Name;
private string IGD;
private string Type;
private string Text;
public A_C()
{
}
public void SetName(string name)
{
name = name.Replace('_', ' ');
name = name.Replace('*', '
‘);
this.Name = name;
}
public string GetName()
{
return Name;
}
public void SetIGD(string IGD)
{
IGD = IGD.Replace(’‘, ’ ‘);
IGD = IGD.Replace(’*’, ’
‘);
this.IGD = IGD;
}
public string GetIGD()
{
return IGD;
}
public void SetType(string type)
{
this.Type = type;
}
public string Gettype()
{
return Type;
}
public void SetText(string Text)
{
Text = Text.Replace(’‘, ’ ‘);
Text = Text.Replace(’*’, ’
');
this.Text = Text;
}
public string GetText()
{
return Text;
}
}