Collision with objects

I have this script attached to a sphere. I have tagged the Sphere too.

What i am am hoping to happen is, when my player collides with the sphere it runs the gui

This is my attempt below, if anyone can help me solve where its going wrong it will be extremely appreciated.

Thanks

var newSkin : GUISkin;
var logoTexture : Texture2D;
private var Winner : boolean = false;

var floatup;
function Start(){
floatup = false;
}

function Update(){
if(floatup)
floatingup();
else if(!floatup)
floatingdown();
}

function floatingup(){
transform.position.y += 0.3 * Time.deltaTime;
yield WaitForSeconds(1);
floatup = false;
}

function floatingdown(){
transform.position.y -= 0.3 * Time.deltaTime;;
yield WaitForSeconds(1);
floatup = true;
}

function OnCollisionEnter (collision: Collision){

if (collision.gameObject.tag == "Sphere"){
var hit = collision.contacts[0];
Winner = true;

}

}

function WinMenu() {
//layout start
GUI.BeginGroup(Rect(Screen.width / 2 - 200, 50, 400, 250));

//the menu background box
GUI.Box(Rect(0, 0, 400, 250), "");

 //logo picture
GUI.Label(Rect(80, 25, 300, 68), logoTexture);

if(GUI.Button(Rect(115, 100, 180, 40), "Play again")) {
Application.LoadLevel("Level 1");
}

//main menu return button
if(GUI.Button(Rect(115, 150, 180, 40), "Main Menu")) {
Application.LoadLevel("Menu");
}

//quit button
if(GUI.Button(Rect(115, 200, 180, 40), "Quit Game")) {
Application.Quit();
}

//layout end
GUI.EndGroup();

}

function OnGUI()
{
if(Winner){
//load GUI skin
GUI.skin = newSkin;

//show the mouse cursor
Screen.showCursor = true;

//run the pause menu script
WinMenu();
}

}


Is your player a character controller?
Then you need to use OnControllerColliderHit

So something like :
function
OnControllerColliderHit (hit : ControllerColliderHit)

{

if(hit.gameObject.tag == “Sphere”)

{

Your code

}

Hope it helps.

Yes i am using the first person player

I changed my a section of my code to what is is below and just get a a lot of errors, having did what the errors messages said it still didnt work.


function OnControllerColliderHit (hit : ControllerColliderHit)

if(hit.gameObject.tag == "Sphere"){
var hit = collision.contacts[0];
Winner = true;

}

}

I changed the code to this but nothing seemed to happen, i did try the top option but did nothing happed theier either.


function OnTriggerEnter (col : Collider)

{

if (col.tag==“Sphere”)

{ Debug.Log(“WATER”);

Winner = true;

}
}

function WinMenu() {
//layout start
GUI.BeginGroup(Rect(Screen.width / 2 - 200, 50, 400, 250));

//the menu background box
GUI.Box(Rect(0, 0, 400, 250), "");

 //logo picture
GUI.Label(Rect(80, 25, 300, 68), logoTexture);

if(GUI.Button(Rect(115, 100, 180, 40), "Play again")) {
Application.LoadLevel("Level 1");
}

//main menu return button
if(GUI.Button(Rect(115, 150, 180, 40), "Main Menu")) {
Application.LoadLevel("Menu");
}

//quit button
if(GUI.Button(Rect(115, 200, 180, 40), "Quit Game")) {
Application.Quit();
}

//layout end
GUI.EndGroup();

}

function OnGUI()
{
if(Winner){
//load GUI skin
GUI.skin = newSkin;

//show the mouse cursor
Screen.showCursor = true;

//run the pause menu script
WinMenu();
}

}