New to Unity, but develop in C# normally. I can't seem to get how / why / where to grab certain elements. For simplicity, I have a top-level game object, say a cube. I add a sphere to the scene as child to the cube. The child sphere (actually more complex), has navigation mesh, animation object, collider and finally a script in C#.
Now, my C# class is comprised of an instance of an C# class on the class. Something like
public class CMyGeneric
{
public void someMethod()
{
// invalid getting to "gameObject" reference
}
}
public class CMyMainScript
{
public CMyGeneric myGeneric;
void Start()
{
myGeneric = new CMyGeneric();
}
void Update()
{
myGeneric.someMethod();
}
}
So, the parent game object is the cube, the child is the sphere, and the CMyMainScript script is attached to the sphere. However, when I try to reference "gameObject" via the CMyGeneric (instance), call within the "someMethod", the "someMethod" doesn't appear to see the overall "gameObject".
Now, how/what am I missing as each thing that gets attached, unity adds to these game objects, and I don't know how to get respective hierarchical levels of where things are even though I know where they are from a relative perspective.