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!
In principle calling another script's function with non-static variables shouldn't be a problem. Is there an objected instantiated of the class that contains DockSign()? EDIT: I guess there are, according to the end of your post. Hmm. Does the function have to be static? Seems odd to me.
– anon48979042I mean, if you have 8 objects and they all share the same attribute-values, I'd just make the attributes static. If they don't share the same values, make the method non-static and call it for each object.
– anon48979042No, there is no object instantiated. It's just those that you see. Reason for the function to be static is because there was an error, but it disappeared now that i removed the static. The error returns for the dockSign.renderer error CS0120: An object reference is required to access non-static member
– AozakiKyuujiSurfaceScript.dockSign' and the occupied bool error CS0120: An object reference is required to access non-static memberSurfaceScript.occupied'Umm so it works now?
– anon48979042My apologies... after removing the static from the function, it really worked..... I hate it when I tried to solve something for so long, and wasted people's time trying to help over a small mistake... sorry man, and thanks for the help ^^
– AozakiKyuuji