Hi, I’ve tried searching around for an hour but couldn’t get an answer… Either my search skill sucks or there isn’t a similar problem.
I’m trying to run ScriptB’s method from Script A. Problem is that ScriptB’s method contains non-static variables like renderer.enabled and a bool.
This is Script A
void HideDockSign ()
{
dropZone1.GetComponent<SurfaceScript>().DockSign();
}
This is SurfaceScript.cs
public bool occupied = false;
public GameObject dockSign;
public static void DockSign ()
{
if (!occupied)
dockSign.renderer.enabled = true;
}
I do not want to define these variables again from Script A because there are other 8 similar items, and that would make a mess. Any ideas? Thanks!
You are trying to call a static function DockSign from a non-static context (a particular instance of the script). To run DockSign from HideDockSign just do:
void HideDockSign ()
{
SurfaceScript.DockSign();
}
On the other hand, a static method like DockSign can’t access non-static variables like dockSign.