Im not sure if I understand your question. When you run a panel, which is just a UI element, you are probably running it from a gameobject that is in your scene. The prefab will also have to be in the scene if you want to access it.
Running functions in other scripts always seems to be something people can’t get their head around. It’s actually not that complicated.
Let’s say we have a script (class) called Janitor. The Janitor class will have some values (variables) like: His name, his age and maybe his favorite bucket to use. The Janitor can also do things (functions/methods) like: sweeping and whistling.
As a (unity)class this would look like this:
public class Janitor : MonoBehaviour{
public string name;
public int age;
public string favoriteBucket;
public void Sweep()
{
Debug.Log("I'm Sweeping");
}
public void Whistle()
{
Debug.Log("I'm Whistling");
}
}
You could place this class on an object and put it in your scene. But how to make the Janitor sweep the floor?
There are multiple ways to make a script access another script. Lets say we have a school class:
public class School : MonoBehaviour{
//You could simply make a public variable and drag the Janitor in, in the inspector.
public Janitor janitor;
//Instead of dragging it in by hand, you could look for the object in the scene:
void Start(){
//By name, your object must be named "Janitor" in the scene
janitor = GameObject.Find("Janitor").GetComponent<Janitor>();
//By tag, your object must have the correct tag (in this case "Janitor").
//Make sure to have only one object with this tag.
janitor = GameObject.FindWithTag("Janitor");
}
}
Now that we found our Janitor class, we can call functions on it:
janitor.Sweep();
janitor.Whistle();
So now that we know the basics, lets apply it to your situation:
Let’s say your Maintenance class has a function called Repair().
To call this function from another gameobject:
//Drag in from inspector:
public Maintenance main;
//Or find the maintenance class in the scene by name:
Maintenance main = GameObject.Find("MaintenanceObject").GetComponent<Maintenance>();
//Call the function
main.Repair();
If this is not the answer to your question, i just need some extra information and we’ll get it working.