Question by
devonzamfir · Mar 21, 2018 at 04:51 PM ·
scene-switchingmanagervoiddefaultunexpected-symbol
"void" error in SceneManager Script
Hello! I am having an error in my C# scene changing script. I have tried everything possible, but it keeps saying that "void" is unexpected. Here is my code:
using UnityEngine.SceneManagement;
using UnityEngine;
void OnCollisionEnter(Collision collision);
{
if (collision.gameObject.tag == "Player")
{
SceneManager.LoadScene ("SceneName");
}
}
Please help me figure this out! I am currently learning C# so I don't know very much about it. Thanks!
Comment
Best Answer
Answer by Bunny83 · Mar 21, 2018 at 06:09 PM
You can't just declare methods inside thin air ^^. Your method has to be inside a class. A MonoBehaviour derived class need to have the same name as the filename. Since we don't know the name of your file we can't tell you how the classname should be. Though it has to loop something like this:
using UnityEngine.SceneManagement;
using UnityEngine;
public class YourFileName : MonoBehaviour
{
void OnCollisionEnter(Collision collision);
{
if (collision.gameObject.tag == "Player")
{
SceneManager.LoadScene ("SceneName");
}
}
}