Hello, im having a problem that i can
t understand, for example in js i have:
//In a script named MenuElement i have:
class MenuElements
{
//My public vars and enums methods etc
}
-------------------------------------------
// And then in another Script named MenuWindows
//code...
var myElements: MenuElements[];
##########################################################################################
And this works perfectly, the problem is when i try to do the same thing in c# it simply doen`t work and gives error “NullReferenceException: Object reference not set to an instance of an object”
// In script MenuElements
public class MenuElements
{
//My public vars enums methods etc
}
//In Script MenuWindow
public class MenuWindow : MonoBehaviour
{
public MenuElements[] myElements;
void OnEnable()
{
if (myElements.Length > 0)
for (var i = 0; i < myElements.Length; i++)
{
//myElements *= new MenuElements();*
myElements*.SetParent(this);*
myElements*.parentSize.x = size.x;*
myElements*.parentSize.y = size.y;*
startPosition = position;
myElements*.percentage = true;*
myElements*.Start();*
}
}
}
I have tried allot of things but i can`t put it to work, what am i doing wrong? My objective is to instantiate the class MenuElements inside MenuWindow, after inserting the number of instances of that class in the inspector.