An object reference is required to access non-static member (CS0120)
using UnityEngine;
using UnityEngine.Networking;
public class Player_NetworkSetup : NetworkBehaviour {
[SerializeField] Camera FPSCharacterCam;
[SerializeField] AudioListener audioListener;
//Use this for Init
void start ()
{
if(isLocalPlayer)
{
GameObject.Find("Scene Camera").SetActive(false);
GetComponent<CharacterController>().enabled = true;
GetComponent<UnityStandardAssets.Characters.FirstPerson.FirstPersonController>().enabled = true;
FPSCharacterCam.enabled = true;
AudioListener.enabled = true;
}
}
}
I done everything and I honestly dont know whats wrong. Please help.
you need to include the complete error message - that way, we can see which line the error relates too. if you're got multiple error messages, include them all...
is this the complete script? line 12 refers to a variable which isn't there...
on a side note, it's Start()
not start()
- unity won't call the latter automatically ;)
If you refer to "isLocalPlayer" it's a variable that's inherited from NetworkBehaviour.
Answer by hexagonius · Feb 14, 2016 at 10:37 PM
I would say at least AudioListener must be fetched with GetComponent to access enabled. Same might apply for FPSCharacterCam. You're accessing them as if they were static, make sure they are, or change to GetComponent if that's what they are