Answer the question
In order to leave comments, you need to log in
How to use a variable from one script in another?
For example, there are two scenes, Scene1 and Scene2
In Scene1 there is a Script1 script, which has a root variable, weighs on the rt object, and in Scene2 there is a Script2 script.
Can you please tell me how to use the root variable in Script2 script??
public class Test : MonoBehaviour
{
Script1 myscript;
void Start()
{
myscript = GameObject.Find("rt").GetComponent<Script1> ();
}
}
Answer the question
In order to leave comments, you need to log in
If both scenes are not loaded at the current moment, then you cannot knock from one to the other.
It's like trying to find a bed in the kitchen. (kitchen, bedroom - different rooms/scenes)
You either make it a static class/variable, or a non-destructible object that will remain in the scene when a new one is loaded.
Or still load both scenes additively..so that you can search in both)
Using the analogy above, you would not build a kitchen or a bedroom. and the house from the kitchen and bedroom, and there they would already be looking for their bed in them)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question