you can give an empty game object any of the colliders,
as found in the component → physics menu
here’s a quick setup:
Make a cube, and in that same physics menu, give it a rigidbody.
Create an empty game object below it and give it a sphere collider
Put this script on the cube, in a script called “s_collide” (important, since it will be looking for that name later):
var collided = false; //initializes a variable we can refer to later
function OnCollisionEnter(){ // when this collides with another collider...
collided = true; // set our variable true.
}
To display text you’ll need to use GUI elements, so we’ll need to set that up on the camera.
There are a few ways of doing this, including broadcasting / sending messages in a hierarchy, but I used object reference here.
Put this script on the camera:
var cube: GameObject; // this lets us drag an object to reference.
private var cube_script;
function Start() {
//the following will give us access to that 'collided' variable
// by giving us all the other script's info in a variable.
cube_script = cube.GetComponent(s_collide);
}
// All of your GUI elements need to be placed in this function,
// such as text on the screen, boxes, or buttons:
function OnGUI() {
//here we look at our other script's "collided" variable:
if (cube_script.collided)
GUI.Label(Rect(20,20,200,20), "Collision Detected!");
// a label is basic, non-interactive text.
else
GUI.Label(Rect(20,20,200,20), "Nothing is Happening.");
}
in order to actually get the camera code to work after you put it on the camera, you’ll need to select the camera, and notice where it has the variable “cube” in the inspector, and there’s an empty spot for a game object. Drag the cube from your object list into that spot.
This will tell the script to refer to that game object.
Now if you place your cube over the empty object in 3D space, it will fall onto it and detect a collision, the camera will notice the collision, and create a label accordingly.
These scripts actually allow the cube to move due to gravity (which can be turned off in the rigid body), and the game object is static, because it was simpler for me to set up.
Sometimes I miss the easy way of doing things, so i apologize in advance if I’ve done that here…