Alright, so I’ve been working on this game for a little while now, but my programmer just graduated (I’m the art guy) so I’ve been left with both jobs… anyway, I’m trying to give myself a crash course in Unity scripting. So, my question of the moment is, how do I reference (I don’t even know what to call them) sub game objects nested within a bigger game object? They’re the different named parts that imported from my modeling program. In the screnshot, you can see what I mean. Anyway, each of those little children has different components, like rigidbody, that I wanna affect individually. This may be a really dumb question, and I apologize for wasting anybody’s time if it is, but any help would be greatly appreciated, thanks.
Looks like your refencing “children”, under their “Parent”
Good luck and keep going when it drives you crazy
(I keep telling myself)
AC
Take a look at http://unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html It gives examples of references other objects.
If you want to go directly after the components look at http://unity3d.com/Documentation/ScriptReference/GameObject.GetComponentsInChildren.html For example, to do something to the rigid bodies of the children objects
var rigidBodies = gameObject.GetComponentsInChildren(RigidBody);
for (var theRigidbody : Rigidbody in rigidBodies)
{
theRigidbody.AddForce(Vector3.up)
}
Worked like a charm guys, thanks for the help.