Boundry destroy problem
I have a 2D asteroid game which spawn moving asteroids (spawn box) from left , right, above and below my main camera view. My original asteroids (objects) where place far away from my main camera and my spawn boxes so it wouldn't come in at i time i didn't give it. I made a boundary box around my main camera and my spawn box so it can destroy any asteroids (objects) that goes beyond that point. but it didn't work. My problem is how can i make a boundary box using a box collider that destroy any objects that goes beyond it. WITHOUT destroying my original asteroids (objects). Here's my boundary script :
using UnityEngine; using System.Collections; public class DestroyByBoundary : MonoBehaviour { void OnTriggerExit(Collider other) { Destroy(other.gameObject); } }
"but it didn't work"
They don't get destroyed, or how does it fail? Or does it destroy them prematurely?
What I mean is: 1) I have original asteroids out side my main camera view 2) I need the original asteroids so that it can spawn clones within my main camera view 3) $$anonymous$$y clone asteroids have a movement script attach to it so it can move in and out of my camera view 4) I want to destroy the clone asteroids once it exits the main camera view, without destroying the original asteroids 5) I've tried doing with a collision box out sides main cameras view, but it didn't work 6) How can I destroy my clone asteroids without destroying the original asteroids
Answer by Statement · Oct 25, 2015 at 10:22 AM
I will assume your "original asteroids" (hereafter called prefabs) are not moving around in your scene. If they are, stop moving your prefabs around at runtime because it doesn't make sense. With the information given, the only way the prefabs would get destroyed would be if they enter and then exit the Boundry.
Consider disabling the prefab gameobject so it is inactive at runtime (no longer moving around, rendering, triggering stuff etc). When you instantiate a asteroid clone from an inactive prefab, active the clone with clone.gameObject.SetActive(true).
The most common way to work with prefabs is to make them assets and not have them hanging around in your scene. With that approach you won't have to worry about the prefabs interacting with your game.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                