For example I have 2 scripts:
I have a boolean in script1 called "boolean" which is set to true
Now I have a second script and want to change the value of "boolean" there. But I have no Idea how.
//script1
bool boolean = true;
For example I have 2 scripts:
I have a boolean in script1 called "boolean" which is set to true
Now I have a second script and want to change the value of "boolean" there. But I have no Idea how.
//script1
bool boolean = true;
You must be a beginner programmer. That is fine. There are dozens of ways and patterns for doing that. Here is one solution.
public class MyScript1 : MonoBehaviour {
public bool myBool = false;
}
public class MyScript2 : MonoBehaviour {
public MyScript1 myscript1;
public void Start() {
myscript1.myBool = true; // assignment
}
}
You need to set myscript1 field of your MyScript2
component. It can be done in Unity Editor's inspector window for MyScript2.