A Little Lost

Having issue where the scene is not loading. I am on VS studio. Also, I couldn’t get the strings to show up on console with previous switch statement lecture. The following is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class CollisionHandler : MonoBehaviour
{
void OnCollisionEnter(Collision other)
{
switch (other.gameObject.tag)
{
case “Friendly”:
Debug.Log(“All good. No problemo.”);
break;
case “Finish”:
Debug.Log(“You didn’t suck!”);
break;
case “Fuel”:
Debug.Log(“You’ll probably need this.”);
break;
default:
ReloadLevel();
break;
}
}

void ReloadLevel()
{
    SceneManager.LoadScene(0);
}

}

Formatting aside, the code doesn’t look like it has any blaring errors. Maybe it’s how it’s been hooked up.

What do you mean, “hooked up”? Like, the way that it is installed on the rocket?

As soon as I add the Reload Level portion, I am unable to run the game. All I see is Sandbox not loaded and I can’t control at all. Also, for some reason even after I assign the script to the rocket, I do not get the strings to display on console whenever the rocket collides with anything.

Could it be that you start the level in a collision with something that causes the level to reload?

1 Like

That really helped. Solved the problem. Thank you.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms