I want to let when my plane touches the powerbox, the powerbox disappears, and the ammo will shoot according to the motion of the plane. However, if I type destroy(gameObject), the function will only destroy the gameobject and the ammo will not shoot. When I delete destroy(gameObject), the powerbox will not be destroyed. But the ammo will only shoot on one side and will not shoot according to the motion of the plane. I have tried so long.
void Update()
{
gameObject.transform.position += new Vector3(0, -0.02f, 0);
ammo2time += Time.deltaTime;
if (hitpowerbox == true)
{
if (ammo2time > 0.30f)
{
Vector3 ammo2_pos = Ship.transform.position + new Vector3(2, 0.1f, 0);
Instantiate(ammo2, ammo2_pos, Ship.transform.rotation);
ammo2time = 0;
}
else
{ }
}
}
void OnTriggerEnter2D(Collider2D col)
{
if (col.tag == "plane")
{
hitpowerbox = true;
}
Destroy(gameObject);
}