Why does this script not execute properly?

Basically I have the script attached to the player and it’s meant to quit the game when the player touches a certain object, however at the moment the player just moves through it. The object is a rigidbody and has is trigger on. Sorry Im new to game development so I may have missed something very simple… code is here:

function OnTriggerEnter( other : Collider ) {    
   if (other.gameObject.tag == "end") {        

I’m not very into this subject, but I think the object that moves into the trigger has to have a rigidbody attached. So in this case, the person. If the trigger is moving into the person, this should have the rigidbody.

It will only work on standalone executables, since quitting the Editor or crashing the Player would not be exactly useful.

void OnTriggerEnter(Collider col)
if(col.gameObject.tag == “Player”)

//acknowledge you are hitting it			
Debug.Log("box 1 was struck !! ");
			//quit out


or… a better way but the same really

using UnityEngine;
using System.Collections;

public class LevelDark : MonoBehaviour {
	//accessible parameter in Unity Inspector
	public float chosenDelay = 5.0f;

	void OnTriggerEnter(Collider col)
			Debug.Log ("level Quit area entered");
			//start coroutine and specify a time to wait
		//if you wanted to move through different levels you might run a coroutine like myChangeLevel where...
		//we could also use string to identify a level but adding each level to the build settings allows us to address them as numeric values like so Application.LoadLevel(0);...
		//...for the first scene in your game, then numerically incremented for each level that follows but to kill the application theh below 	method call is what youd wnat i reckon
    		//Application.LoadLevel ("Begin");

	IEnumerator MyQuitLevel(float delay)
			//look at console during play to see this pop up if you want
			Debug.Log ("IENMUERATOR ENTERED, you are about to get tha F outta here");
		//wait for some time in seconds , fed by the delay float type , you	
	    yield return new WaitForSeconds(delay);
		//quit out now countdown has passed


The above code shoudl work fine, but is c# and in my opinion a better code level to learn as is a bit stricter and causes one to ensure their coding is not in danger of becoming (wish i could think of a better description but) potentially secretive like and sloppy… (I love js, so not favouritism, just practical application of the leaner method to execution of code)
ah what do i know eh :slight_smile:
Hope this helps in some small way. Happy to be corrected if anything is wrong, but think is okay…
Your main issue would be to attahc this to something like an empty gamepbject that were the parent of the object you want to interact with…This empty object could then have a box collider component added to it and have the tick box stating “is Trigger” ticked.

you would then place you interacting object inside the empty object (this alows you to have rigid body etc on your interactive object if needed)

After this, you should place your OnTriggerEnter script on the empty game object.
and for joy and love and a definite interaction, make your is Trigger box collider on the empty game object BIGGER than you child object that you want to interact with…

Now theres another way too, where by with the above method you could attach a collision enter method to the child interactive object and then use the script on the empty game object to do something like gameObject.FindChild(“ExitBox”).SendMessage(“OnCollisionEnter”); where you could write an exit routine…but i will let you discover that joy
Like i said, hope you get something from this brain spill out, sorry if its a bit messy :stuck_out_tongue: