Stuck Unity 6 Section 3 Rocket Boost

After setting up Invoke in section 49 in Udemy. Invoke could not call the on the method because it was in the wrong class. Rick added a bracket and used a shortcut. I tried the same but it didnt work. No matter how I try to restructure my classes they always lead to errors. Here is what my code looks like.
using UnityEngine;

using UnityEngine.SceneManagement;

public class CollisionHandler : MonoBehaviour

{

private void OnCollisionEnter(Collision other)

{

switch (other.gameObject.tag)  

    {

    case "Friendly":

        Debug.Log ("this is friendly");

        break;

    case "Finish":

        Debug.Log("This is the goal");

        LoadNextLevel();

        break;

        default:

        Invoke ("ReloadLevel", 2f);

        break;

    }

}

private static void ReloadLevel()

{

    int currentScene = SceneManager.GetActiveScene().buildIndex;

    SceneManager.LoadScene(currentScene);

}

private static void LoadNextLevel()

{

    int currentScene = SceneManager.GetActiveScene().buildIndex;

    int nextScene = currentScene + 1;

    if (nextScene == SceneManager.sceneCountInBuildSettings)

    {

        nextScene = 0;

    }

   

    SceneManager.LoadScene(nextScene);

}

}

SOLVED Turns out I extracted a method instead of making one like Rick did, removing the “static” from the class fixed it for me.

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

Privacy & Terms