- Home /
Assets/Scripts/NetworkManager.cs(47,48): error CS0120: An object reference is required to access non-static member `PhotonView.isMine'
Please help! The lead programmer in our team thought I should learn programming (I'm an artist/modeler). I'm using quill18creates' tutorial to make a multiplayer fps in unity. Just something simple, not anything major. I'm really stuck right now, and I can't figure out what's wrong. I realize similar questions have been asked before, but I'm too stupid to understand anything.
using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour {
SpawnSpot [] spawnSpots;
// Use this for initialization
void Start () {
spawnSpots = GameObject.FindObjectsOfType<SpawnSpot> ();
Connect ();
}
// Update is called once per frame
void Update () {
}
void Connect () {
PhotonNetwork.ConnectUsingSettings ("v0.0.1");
}
void OnGUI () {
GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString ());
}
void OnJoinedLobby () {
Debug.Log ("OnJoinedLobby");
PhotonNetwork.JoinRandomRoom ();
}
void OnPhotonRandomJoinFailed () {
Debug.Log ("OnPhotonRandomJoinFailed");
PhotonNetwork.CreateRoom (null);
}
void OnJoinedRoom() {
Debug.Log ("OnJoinedRoom");
SpawnMyPlayer ();
}
void SpawnMyPlayer() {
SpawnSpot mySpawnSpot = spawnSpots [Random.Range (0, spawnSpots.Length)];
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate ("Capsule", mySpawnSpot.transform.position, Quaternion.identity, 0);
Debug.Log ("Instantiated");
if (PhotonView.isMine) {
((MonoBehaviour)myPlayerGO.GetComponent ("Player Movement")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent ("Playerlook Script")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent ("Mouse Look Script")).enabled = true;
}
}
}
I've tried everything I can think of. Nothing seems to work.
Also note that the other scripts are JavaScript, whereas this one's C#
I can't help you too much, I don't know Photon, but, as non-programmer, when you see "An object reference is required" message, this mean in general you have to use, somewhere, something like "new Object" to ask object for functions like Object.DoSomething(). It's like "A cupe it's required to drink". In your code, somewhere is no 'cupe'; $$anonymous$$aybe it's something wrong with Photon objects (if there is the line 47; look at line 47, character 48 on original code), or myPlayerGO names or instantiations (aka object creations); note "($$anonymous$$onoBehaviour)" along of an object it's not an usual cast (conversion from a type to other type); this may induce some problems.
Thanks nastasache. I think I understand more clearly what the error is now.
Answer by ianmcmillian · Dec 30, 2013 at 09:48 PM
a) Double check the name of the scripts. Spaces etc.
b) replace
((MonoBehaviour)myPlayerGO.GetComponent ("Player Movement")).enabled = true;
by
myPlayerGO.GetComponent(Player Movement).enabled = true;
When I do that, it just says Unexpected Token: $$anonymous$$ovement, Script, Look, and Switch.
I followed the tutorials from http://www.youtube.com/watch?v=0h786_PmGDQ . There he has also the problem with javascript rambling with c#. He did as you posted with the ($$anonymous$$onoBehaviour). I followed his order, did the same and had another error. Finally after I reverted to myPlayerGO.GetComponent(Player $$anonymous$$ovement).enabled = true;
the error was gone. But then the Nullreference error occured. I watched over it and found that the script that should be called (in your case = Player $$anonymous$$ovement) was mismatched in Unity Inspector and $$anonymous$$onobehaviour editor.
e.g. whitespaces' typo. Look carefully.