get variable

Hi there,

i use a filebrowser and in this filebrowser there is a varible (path) which descirbes where to find the document i need to work with.
now i want to use the information in the document as it is necessary for my game. so i need to call the “Path” in one script in my second script
how do i do that?
it is no gameobject so i have no idea how to access it otherwise

Hi!
You can use one variable to another by make public static. Then you can call that variable in other class by make Class Object.
for Example:
public Class Test1
{
public static String path;
}
public class Test2
{
Test1.path;
}
U can set change Path value from anywhere anytime. By this way.

@game4444 is correct that you can make it public and static. There are drawbacks to doing that, though maybe they don’t apply with a file browsers since you will probably only ever use one at a time.

An alternative is to create a public field with the same type as your file browser script and then use the inspector to connect them by dragging the file browser game object into the editor for that field. If you do that a public property or field can be used to communicate between the two.

public class UsesFileBrowser : MonoBehaviour
{
  public FileBrowser Browser;

  public string LoadData()
  {
    return File.ReadAllText(Browser.SelectedPath);
  }
}

public class FileBrowser : MonoBehaviour
{
  public string SelectedPath { get; private set; }

  // other stuff does the actual file browsing
}