One special question

Please help! My landing pad in Hierarchy is a model, consisting of several meshes. So I tag the Parent object as ‘Friendly’. But I can not put the same tag for child objects in automatic manner. Only manually. Can it be fixed anyway? Please help!

You could always use layering rather than flagging the pad as friendly in script. Set up a friendly layer and add something like

if (gameObject.layer != LayerMask.NameToLayer("Friendly")) {
    // blow up or something
}
else {
    // maybe some kind of special treatment for friendly objects
}

to your collision code.

It’s also possible to script a merged mesh onto the parent object from its children and disable the child meshes, but it’s far more involved, and I don’t understand it well enough to actually explain what’s going on, so I’m not really willing to share the hacky mess I made to do such things.

Just thought of an option C … Add a serializable bool isParentOfFriendly to whichever script it is that the pad uses, and well…

[SerializableField] bool isParentOfFriendly = false;
public bool IsParentOfFriendly {
    get {
        return isParentOfFriendly;
    }
}

void Start() {
    if (gameObject.GetComponentInParent<YourScriptObject>().IsParentOfFriendly) {
        // set your friendly flag
    }
    // do the rest of your Start method
}

I’m not yet to this point in the course, so what all you’re interacting with, I’m not really sure, but I can’t think of a reason that wouldn’t work

Thank you! Will try to do it in Project!

5am me, on no sleep, without an IDE open, apparently writes some sketchy stuff. Ostensibly, you’d be checking what your ship collided into, so you’d need collision.gameObject.layer rather than gameObject.layer for option A, and option C looks like it would need to check transform.parent for null before trying to fetch a component to avoid null reference exceptions.

Privacy & Terms