Use Gui with 2 functions help?

I have this script when you hit this object a gui box appears. But it doesn’t work because I have to functions. Here is the script.

var MenuActive:boolean = false; 
var collision : Collision;
function OnCollisionEnter(collision : Collision) {
    // Debug-draw all contact points and normals
    for (var contact : ContactPoint in collision.contacts) {
        Debug.DrawRay(contact.point, contact.normal, Color.white);
    }
	if (collision.relativeVelocity.magnitude > 2)

unlockedLevels.levelOn++;
print ("Hit Target");
function OnGUI () {
if (MenuActive == true) 
{      
   //show mouse cursor 
   Screen.showCursor = true;} 
   else {Screen.showCursor = false;} 
    
   if (MenuActive == true){ 
    
     // Make a background box 
   GUI.Box (Rect ((Screen.width-200)/2,80,200,180), "Space BreakOut: Training Mode Complete"); 
   //First button goes to  
   if (GUI.Button (Rect ((Screen.width-150)/2,110,150,20), "To Level Select")) { 
      Application.LoadLevel ("Level Select"); 
     } 
     //Second button goes to second level 
      if (GUI.Button (Rect((Screen.width-150)/2,190,150,20), "To Next Level")) { 
      Application.LoadLevel ("Level 2"); 
   } 
   }
}
}

So can anyone help me?

Wow, that’s a mess, very hard to read.

It looks like your most immediate problem is that your OnGUI function is actually inside of your OnCollisionEnter function, which isn’t valid. You cannot have nested functions.

I tried, briefly, to fix it for you, but there are other problems in there as well, and the formatting and spacing made it harder to parse than I have the mental bandwidth for at the moment, so I’ll leave that as an exercise for you.

.

Well I tried changing it.

var MenuActive:boolean = false; 
var collision : Collision;
	
function OnGUI () {
if (collision.relativeVelocity.magnitude > 2)
{
unlockedLevels.levelOn++;
print ("Hit Target");
if (MenuActive == true) 
{      
   //show mouse cursor 
   Screen.showCursor = true;} 
   else {Screen.showCursor = false;} 
    
   if (MenuActive == true){ 
    
     // Make a background box 
   GUI.Box (Rect ((Screen.width-200)/2,80,200,180), "Space BreakOut: Training Mode Complete"); 
   //First button goes to  
   if (GUI.Button (Rect ((Screen.width-150)/2,110,150,20), "To Level Select")) { 
      Application.LoadLevel ("Level Select"); 
     } 
     //Second button goes to second level 
      if (GUI.Button (Rect((Screen.width-150)/2,190,150,20), "To Next Level")) { 
      Application.LoadLevel ("Level 2"); 
   } 
   }
}
}