Hi there,
I’ve been struggling with my code and I can’t find the reason for it to not work. After hours of trying to fix it I decided to ask for some help.
The issue is that when I land on the Landing Pad it says:
Trying to Invoke method: CollisionHandler.LoadNextlevel couldn’t be called.
StartSuccessSequence() is pretty much the same thing as StartCrashSequence() , however it doesn’t work for some reason. I’ve checked my curly brackets and they seem fine. Here’s the code:
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CollisionHandler : MonoBehaviour
{
[SerializeField] float crashDelayTimer = 1f;
[SerializeField] float loadDelayTimer = 1f;
void OnCollisionEnter(Collision other)
{
switch (other.gameObject.tag)
{
case "Friendly":
Debug.Log("This thing is friendly");
break;
case "Finish":
StartSuccessSequence();
break;
default:
StartCrashSequence();
break;
}
}
void StartSuccessSequence()
{
GetComponent<Movement>().enabled = false;
Invoke("LoadNextlevel", loadDelayTimer);
}
void StartCrashSequence()
{
GetComponent<Movement>().enabled = false;
Invoke("ReloadLevel", crashDelayTimer);
}
void ReloadLevel()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentSceneIndex);
}
void LoadNextLevel()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
int nextSceneIndex = currentSceneIndex + 1;
if (nextSceneIndex == SceneManager.sceneCountInBuildSettings)
{
nextSceneIndex = 0;
}
SceneManager.LoadScene(nextSceneIndex);
}
}
Any help would be appreciated!