So I’ve been developing this game in which the player must shoot targets that can fire back. one of the targets is a parent of child object which is a large invisible rectangle with the soul purpose of informing the parent if it has found the player so it can attack. I also put a script in the parent that tells it that if the player successfully shoots at it without missing that it should destroy itself. But for some reason both the parent and the child can trigger this. that means with my parent can be destroyed from too far away.
in this image the blue arrow points to my parent object, the red points to the child which informs the parent if it has found the player or not and the arrow in black points at the player. (the payer can shoot up but when it hits the child object it triggers the parent to destroy itself!)
Code that kills jet upon hit:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class JetKill : MonoBehaviour {
// Use this for initialization
if (collision.CompareTag("playerShoot"))//player shoot is the tag for the players projectile
{
Destroy(gameObject);
}
}
,So I’ve been developing this game where the player has to shoot targets that can fire back. one of the targets is a parent object with a child paired to it that is a invisible wall meant to detect if the player is in its range. Now when I’ve scripted my parent object to destroy itself upon detecting the players bullets but it gets triggered even when they hit the child of the parent which I don’t want
In that image the blue arrow points towards my parent object (the jet), the black one points to the player and the red one points towards the player detector. If you need anymore details ill provide as much as possible, thank you!
My parent object code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class JetKill : MonoBehaviour {
public GameObject BOOM;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("jetKill")) //Kill jet at end
{
Destroy(gameObject);
}
if (collision.CompareTag("playerShoot"))
{
Instantiate(BOOM, transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
}
Although applied on parent object it for some reason gets triggered by child