When colliding with Trigger, i’d like to delete the object I hit, aswell as the objects parent…
It’s not quite working though:
function OnTriggerEnter(otherObject: Collider){
if(otherObject.gameObject.tag == "Player"){
playerScript.playerScore +=100;
Destroy (gameObject);
Destroy (parent.gameObject);
}}
Any ideas? Thank you in advance, sorry, I’m still the novice
save
2
Try to only use:
Destroy(transform.parent.gameObject);
or
Destroy(transform.root.gameObject);
If you'd like to keep the current gameObject but just remove the parent then try:
var deleteParent : GameObject = transform.parent;
transform.parent = null;
Destroy(deleteParent);