how to detect if one object is touching another

I want to change levels…So everytime that the player touches the EndLevel point it will start another level…

this is what i’ve come to so far

function OnCollision(col : Collision) {
	if (col.gameObject == "Player" ) {
    	Application.LoadLevel (1);
    }
}

But it doesn’t seem to work , i get no errors , yet nothing is happening in the actual game.

This is what i used for the next level portal:

void OnTriggerEnter2D(Collider2D other)
{
	if(other.gameObject.tag == "Player")
	{
		DontDestroyOnLoad(other.gameObject);
		Application.LoadLevel("ENTER LEVELNAME HERE");
	}
}

This is C# and sorry about that. You must also tag the player as “Player”. What this is doing is running this function whenever anything touches it, and if the tag is “Player” it will load the selected level.

P.S If you have a 3D game, just Change “OnTriggerEnter2D” to “OnTriggerEnter”, and change “Collision2D” To “Collision”.

Thanks! -Alec

You need to write it like this:

function OnCollisionEnter(col : Collision) {
    if (col.collider.name == "Player" ) {
        Application.LoadLevel(1);
    }
}

or if you want to use it with TAG:

function OnCollisionEnter(col : Collision) {
    if (col.collider.tag == "Player" ) {
        Application.LoadLevel(1);
    }
}

Hi, you are comparing a gameObject and a string, try to use col.gameObject.name or col.gameObject.tag instead

Regards, BPR

Thanks both for your answers… It seems I cant set the unity correctly to behave according to the script…What I basicly did was adding this script to the a cube i wanted to use as a winpoint… But when the player touches it , nothing happens