I'm making a top down perspective game with a gunner automatically moves on a pre-set path, and you shoot and destroy targets to remove barriers. The idea is that you control the bullet's direction after firing and it can pass through laser gates, but the gunner cannot. There are several targets and barriers.
What I want: If the bullet hits the local target, the local target and local barrier are destroyed.
I tried making each target and barrier as children of empty game objects, and I attempted to destroy the empty parent to solve this problem. Please advise.
(Showing only relevant code)
using UnityEngine;
using System.Collections;
public class MagicBulletScript : MonoBehaviour {
public Transform magicBulletTransform;
void Start () {
magicBulletTransform = transform;
}
void OnTriggerEnter (Collider other){
var progressParent = this.transform.parent.gameObject;
if (other.gameObject.CompareTag("Obstacle")){
Destroy (this.gameObject);
}
if (other.gameObject.CompareTag("Target")){
Destroy (progressParent.gameObject);
Destroy (other.gameObject);
}
}
}