NullReferenceException: Object reference not set to an instance of an object
CollisionHandler.StartCrashSequence () (at Assets/Scripts/CollisionHandler.cs:45)
CollisionHandler.OnCollisionEnter (UnityEngine.Collision other) (at Assets/Scripts/CollisionHandler.cs:30)
This is my script
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CollisionHandler : MonoBehaviour
{
[SerializeField] float levelLoadDelay = 2f;
[SerializeField] AudioClip success;
[SerializeField] AudioClip crash;
AudioSource Audio;
void start()
{
Audio=GetComponent<AudioSource>();
}
void OnCollisionEnter(Collision other)
{
switch (other.gameObject.tag)
{
case "Friendly":
Debug.Log("This place is friendly");
break;
case "Finish":
StartSuccessSequence();
break;
default:
StartCrashSequence();
break;
}
}
void StartSuccessSequence()
{
Audio.PlayOneShot(success);
GetComponent<Movement>().enabled = false;
Invoke("LoadNextLevel", levelLoadDelay);
}
void StartCrashSequence()
{
Audio.PlayOneShot(crash);
GetComponent<Movement>().enabled = false;
Invoke("ReloadLevel", levelLoadDelay);
}
void LoadNextLevel()
{
int currentscene = SceneManager.GetActiveScene().buildIndex;
int NextScene=currentscene+1;
if(NextScene==SceneManager.sceneCountInBuildSettings)
{
NextScene=0;
}
SceneManager.LoadScene(NextScene);
}
void ReloadLevel()
{
int currentscene=SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentscene);
}
}