- Home /
Disable a script when another is active
So I have got two scene change scripts, both which are attached to two different game objects. But for some reason, one script affects both game objects. So I am trying to temporarily disable one of the scripts when the other script is active on the other game object. Here is what I have but this is returning the error, "BasketballSceneChange' is a type, which is not valid in the given context".
void Update()
{
**GameObject.Find("pPrism1").GetComponent(BasketballSceneChange).enabled = false;**
if (Input.GetMouseButtonDown(0) && SceneManager.GetActiveScene().name == "MWalk")
{
SceneManager.LoadScene("SWalk");
}
if (Input.GetMouseButton(0) && SceneManager.GetActiveScene().name == "SWalk")
{
SceneManager.LoadScene("Football");
}
if (Input.GetMouseButton(0) && SceneManager.GetActiveScene().name == "Basketball")
{
SceneManager.LoadScene("BWalk");
}
if (Input.GetMouseButton(0) && SceneManager.GetActiveScene().name == "BWalk")
{
SceneManager.LoadScene("MWalk");
So I also posted the question on stack overflow and got an answer. Heres the link for anyone who needs help as well. https://stackoverflow.com/q/49467237/5993513
Answer by tormentoarmagedoom · Mar 26, 2018 at 08:23 AM
Why just dont create a bool variable and check it vai "if" at the begining of each "LoadScene" to allow/prevent all the script to execute when you want?
You know, i supose you have 2 diferent scripts because player can go to 2 different scenes. So there are some things to decide which scene can be loaded.
Bye :D
Your answer
![](https://koobas.hobune.stream/wayback/20220612155302im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to disable blurOptimized from another script 0 Answers
Script isn't disabling? 1 Answer
Unable to disable the MouseLook script 2 Answers
How use the function Application.LoadLevelAsync(level); 1 Answer
Trouble isolating IOS runtime error UnityPreload (41): EXC_BAD_ACCESS(code-1, address=0x20) 0 Answers