I have a game object whose prefab is structured a very specific way. It is a conveyor belt. I intend to arrange them end-to-end and animate them all at once using a script. Right now I am trying to get the normalized heading vector between two children, TargetStart and TargetEnd (see images below):
You can see that both of these objects are children of the prefab's first child. Because all of these instances will be structured the same, I want to compute the heading for the conveyor belt by accessing the locations of these children by their indices relative to the parent (which sounds like it should be simple and should be more efficient than searching by name or tag). I am anticipating a structure like this (pseudo-code):
// heading = targetEnd's position - targetStart's position vector3 heading = gameObject.GetChild.position - gameObject.GetChild.position; vector3 direction = heading / heading.magnitude;
How can this be done? I would like to know this so I can access any child I need to for any object by the child's index.