Collision To Change Scene

I’m try to make it so if my player collides with a Mesh that I imported, the game will change scenes to the scene “CInt”

But I keep getting this error “Can’t add component ‘OnCollision’ because it doesn’t exist. Check to see if the file name and class name match.”

Here’s the code for reference.

Also I dont know if it matters but I’m trying to attach the script to the mesh I was the player to collide too

using UnityEngine;
using System.Collections;

public class OnCollision : MonoBehaviour
{
Application.LoadLevel("CInt#");
}

With all due respect, you have obviously not understood the basics of programming in C#. I suggest you to learn them.

You should also change the name of the Script.

1 Like
using UnityEngine;
using System.Collections;

public class OnCollision : MonoBehaviour
{
Application.LoadLevel("CInt#");
}

[/QUOTE]

As mentioned above, you will need a Class to actually put your methods into. And you do want to call that method which is what is done in the post over mine.

A good way to see if something works before you start putting in a lot of code is to debug.log to see if the player is actually coliding with the mesh as well.

Try to use the scripting manual as well to Get some good examples of how to write code lines.

1 Like