Hello everybody,
I’m having trouble accesing a variable inherited from a class.
This is my class:
using UnityEngine;
using System.Collections;
public class RecetaInitializer : MonoBehaviour {
public RecetaConstructor[] Receta;
void Start () {
Receta = new RecetaConstructor[9];
for (int i = 0; i < Receta.Length; i++)
{
Receta *= new RecetaConstructor();*
-
}*
-
Receta[0].AddReceta(1, "Huevo Duro", "agua,huevo");*
-
Receta[1].AddReceta(2, "Papas Fritas", "papa,aceite");*
-
Receta[2].AddReceta(3, "Omelette", "huevo,queso,jamon");*
-
Receta[3].AddReceta(4, "Licuado De Banana", "leche,banana");*
-
Receta[4].AddReceta(5, "Chocolatada", "leche,chocolate");*
-
Receta[5].AddReceta(6, "Fideos Con Queso", "fideos,queso");*
-
Receta[6].AddReceta(7, "Pancho", "pan,salchicha,queso");*
-
Receta[7].AddReceta(8, "Pizza", "pan,queso,jamon,tomate");*
-
Receta[8].AddReceta(9, "Hamburguesa", "pan,paty,queso,lechuga,tomate");*
-
// Debug.Log(Receta[7].GetRecetaName());*
-
}*
}
Now, I want to access from another script the variable Receta. To achieve this I created another class that I use to manage my game:
using UnityEngine;
using System.Collections;
public class MenuGUI : RecetaInitializer{
-
public RecetaConstructor Receta;*
-
// RecetaConstructor is a class I have which works fine, it lets me create different recipes for my game.*
-
void Start()*
-
{*
-
Receta = gameObject.GetComponent<RecetaInitializer>().Receta;*
-
PrepareGame();*
-
}*
-
private void PrepareGame()*
-
{*
-
Debug.Log(Receta[0].GetRecetaName());*
-
// GetRecetaName() is self-explanatory, given the index it returns the name of the Recipe/Receta*
-
}*
}
I’m clearly missing something here, ad Unity gives me a nice “Object reference not set to an instance of an object”.
I also tried by not inheriting the class and add it with AddComponent and then RecetaConstructor[] Receta = gameObject.GetComponent().Receta; But the result is the same.
Any hint?
Thanks very much!