im unable to fix this error on unity where the colliders for my rocket stop working and the scenes dont advance or reset after implementing the audiosource into the collider script i can send the link to the script if you know a solution to this problem many thanks
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CollisionBehaviour : MonoBehaviour
{
[SerializeField] float LevelLoadDelayTime = 2f; // member level variable which holds the delay time of whent he next scene should start
[SerializeField] AudioClip Success;
[SerializeField] AudioClip Crashed;
AudioSource audioSource;
void start()
{
audioSource = GetComponent<AudioSource>(); // cached variable is formed here
}
void OnCollisionEnter(Collision other) // when other (the player) collides with a boxcollider
{
switch (other.gameObject.tag) // switch operator "the if statement subsitute for tags"
{
case "Friendly": // checks the tags
Debug.Log("This is friendly");
break; // this is when it should end
case "Finish":
SuccessSequenceActive();
break;
default:
YouCrashed(); // new method for playing the crash sequence
break;
}
}
void SuccessSequenceActive() // new method for when the player successfully reaches the other platform
{
audioSource.PlayOneShot(Success);
// finds the cached variable and plays the success tune
GetComponent<RocketMovement>().enabled = false; // deactivates script for movement
Invoke("LoadNextLevel" , LevelLoadDelayTime); // delays the loadnextlevel method through the variable LevelLoadDelayTime
}
void YouCrashed() // new method for when the player crashes
{
audioSource.PlayOneShot(Crashed);
GetComponent<RocketMovement>().enabled = false; // disables the movement script when the YouCrashed method plays
Invoke ("RestartFromCheckPoint" , LevelLoadDelayTime); //invoke allows the method to be delayed before it is activated
}
void LoadNextLevel() // new method created whereby the user is taken to the next level/scene when they have completed the course
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex; // current scene index is set to 0 so we will ad 1 to go to the next level
int nextSceneIndex = currentSceneIndex + 1; // by adding this line of code, the game recognises what the next scene is
if (nextSceneIndex == SceneManager.sceneCountInBuildSettings) // checks if the sceneindex variable is the same number as scenes in the game...
{
nextSceneIndex = 0; // loops back to the start scene (aka first level)
}
SceneManager.LoadScene(nextSceneIndex); // Scenemanager allows me to load a saved scene from unity
// the scene being loaded is the one held in the variable
}
void RestartFromCheckPoint() // new method is declared
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex; // variable currentsceneindex will contain the active scene from scene manager
SceneManager.LoadScene(currentSceneIndex); // the variable currentsceneindex will load the active scene +1 (aka the next level)
}
}