- Tutorials
- Space Shooter tutorial
- Boundary
Boundary
Checked with version: 5.1
-
Difficulty: Beginner
Creating a bounding box to destroy any object that leaves the game area.


Boundary
Beginner Space Shooter tutorial
Please note that this project was developed for Unity version 4. It currently works, and has been checked, with Unity version 5.1. Please turn annotations on while watching the video, as we can add annotations to the videos when there are discrepancies between the recorded content and the current version of Unity.
Get the Upgrade Guide for Unity 5 here.
Please refer to the Official Q&A Page on the Forums for an Upgrade FAQ and to ask any questions.
DestroyByBoundary
Code snippet
using UnityEngine;
using System.Collections;
public class DestroyByBoundary : MonoBehaviour
{
void OnTriggerExit(Collider other)
{
Destroy(other.gameObject);
}
}
#pragma strict
function OnTriggerExit(other : Collider)
{
Destroy(other.gameObject);
}
import UnityEngine
import System.Collections
public class DestroyByBoundary(MonoBehaviour):
private def OnTriggerExit(other as Collider):
Destroy(other.gameObject)
Related tutorials
- Colliders (Lesson)
- Colliders as Triggers (Lesson)
Related documentation
- Box Collider (Manual)
- Collider (Script Reference)
- Collider.OnTriggerExit(Collider) (Script Reference)