object reference is required to access non-static member - What does this mean?
if (dev05State == true){
Sending.sendBlue (); //Surveillance Mode
SurveillanceModeManager.TogglePlay ();
I'm trying to call another script to have it activate something but I get this error message:
Assets/Scripts/CountdownTimerManager.cs(124,57): error CS0120: An object reference is required to access non-static member `SurveillanceModeManager.TogglePlay()'
as meat5000 explained. `Surveillance$$anonymous$$ode$$anonymous$$anager.TogglePlay()' will only work if it's a public static function. If it's not, then you need an instance of Surveillance$$anonymous$$ode$$anonymous$$anager. For example:
Surveillance$$anonymous$$ode$$anonymous$$anager smm = FindObjectOfType<Surveillance$$anonymous$$ode$$anonymous$$anager>();
smm.TogglePlay();
smm is the instance of Surveillance$$anonymous$$ode$$anonymous$$anager
Thanks @Jessespike That was very helpful to have a code sample. I added in the extra line for the animation and it works perfectly.... not sure if it would work across scene changes as I ended up moving this panel into the main scene and just making it a slide in screen but the scripts at least talk to each other now. $$anonymous$$uch $$anonymous$$UCH thanks for that :)
if (dev05State == true){
Sending.sendBlue (); //Surveillance $$anonymous$$ode
Surveillance$$anonymous$$ode$$anonymous$$anager smm = FindObjectOfType<Surveillance$$anonymous$$ode$$anonymous$$anager>();
smm.TogglePlay();
smm.PlayLEDLightsAnimation();
}
Answer by meat5000 · Dec 03, 2015 at 05:31 PM
You attempt to make a call to an object which has not been referenced. This only works with static members. If something is static it is Unique and can be accessed from anywhere. A non-static member requires you to tell the compiler where/what it is.
You already know this :D