This error is popping up as a result of me trying to call a function in one script from another I’m not sure what I’m doing wrong and I’ve tried a few different work arounds and none have worked for me. Here is the code I’ve written.
MainCameraAudio script
using UnityEngine;
using System.Collections;
public class MainCameraAudio : MonoBehaviour {
bool gameOverTest = false;
public Instantiation script;
void Awake(){
gameOverSource = AddAudio(gameOver, false, false, 1);
}
void Start () {
script = (Instantiation)this.GetComponent(typeof(Instantiation));
}
void Update () {
if(script.CheckGameOver() && gameOverTest != true){
audio.PlayOneShot(gameOverSource.clip);
gameOverTest = true;
}
}
Don’t worry about the AddAudio() function that’s not the problem here. As well as the variable declarations, those are there I’m just not including them on here. The gameOverSource is an AudioSource with an audio clip attached to it. I’m trying to test if gameOver is true by accessing a script on this same object called Instantiation.
Instantiation script checkGameOver method
public bool CheckGameOver(){
if(gridEnvironment[playerCol, playerRow].tag == "Pit"){
Debug.Log("GAME OVER YOU DEAD");
dead = true;
}
return dead;
}
I get the error and it says it’s on the if statement in the method CheckGameOver() here. Am I accessing the script incorrectly or am I completely missing something. It’s been bugging me for awhile now. Any help is appreciated, if you need to see more I’m willing to put the full scripts up but they are long and doubt that they would help at all, I’m fairly sure that the problem lies with the way that I’m calling the script. Thanks for your time.