- Home /
Question by
kaplica · Apr 07, 2017 at 02:56 PM ·
gameobjectgetcomponentcomponentstack
Unable to get component from a gameobject
I am making a simple menu system using stack,
based on the parameters passed in, if its a view, it will push the view to the stack, and then if its a string then it will try to find the gameobject of that string's name and then the component of it, and then pass the view component to the stack. So you can use navigate.Push("CategoryView"); or navigate.Push(CategoryView);
This is the code of Push
public void Push<T>(T obj) {
View view = null;
if (obj.GetType () != typeof(View)) {
if (obj.GetType () == typeof(System.String)) {
string goName = obj as string;
Debug.Log (goName);
GameObject go = GameObject.Find (goName);
Debug.Log ("Found GameObject's name " + go.name);
view = go.GetComponent<View> ();
Debug.Log ("WE FOUND THE VIEW " + view.name + " BY STRING... ITS: " + go.name);
} else {
Debug.LogWarning ("The navigation type passed in is NOT a string or view.");
}
} else {
view = obj as View;
}
if (!_uiStack.Contains (view)) {
_uiStack.Push (view);
UpdateUI ();
}
}
For some reason, view is always null
Comment