Hello, i am following a Tutorials Series on YouTube (Aggregat Games) and i typed everything like them but i get this weird error “Assets/Scripts/NetworkManager.cs(120,56): error CS0176: Static member `LevelManager.SpawnPoints’ cannot be accessed with an instance reference, qualify it with a type name instead” i tried everything to fix it but i can´t find the problem pls help me this error sucks ^^
here are my Scripts if someone could please correct me that would be very nice!
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class NetworkManager : MonoBehaviour {
public string PlayerName;
public string MatchName;
public static NetworkManager Instance;
public List<Player> PlayerList = new List<Player>();
public Player MyPlayer;
public GameObject SpawnPlayer;
public bool MatchStarted;
public List<Transform> SpawnPoints = new List<Transform>();
//public bool MatchLoaded;
// Use this for initialization
void Start ()
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
// Update is called once per frame
void Update ()
{
//PlayerName = PlayerPrefs.GetString("PlayerName");
}
public void StartServer(string ServerName, int MaxPlayers)
{
Network.InitializeSecurity();
Network.InitializeServer(MaxPlayers,25565,true);
MasterServer.RegisterHost("Bulletrain",ServerName,"");
Debug.Log ("Started Server!");
}
void OnPlayerConnected(NetworkPlayer id)
{
//networkView.RPC("Server_PlayerJoined",RPCMode.Server, PlayerName, id);
foreach(Player pl in PlayerList)
{
networkView.RPC("Client_PlayerJoined", id, pl.PlayerName, pl.OnlinePlayer);
}
}
void OnServerInitialized()
{
Server_PlayerJoined(PlayerName, Network.player);
}
void OnConnectedToServer()
{
networkView.RPC ("Server_PlayerJoined", RPCMode.Server,PlayerName, Network.player);
}
void OnPlayerDisconnected(NetworkPlayer id)
{
Debug.Log("A Player is leaving");
networkView.RPC("RemovePlayer", RPCMode.All, id);
Network.RemoveRPCs(id);
Debug.Log("A Player left");
}
void OnDisconnectedFromServer(NetworkDisconnection info)
{
Debug.Log("You are leaving");
PlayerList.Clear();
Debug.Log("You left");
}
[RPC]
public void Server_PlayerJoined(string Username,NetworkPlayer id)
{
networkView.RPC ("Client_PlayerJoined", RPCMode.All,Username, id);
}
[RPC]
public void Client_PlayerJoined(string Username,NetworkPlayer id)
{
Player temp = new Player();
temp.PlayerName = Username;
temp.OnlinePlayer = id;
PlayerList.Add(temp);
if(Network.player == id)
{
MyPlayer = temp;
Network.Instantiate(SpawnPlayer,Vector3.zero,Quaternion.identity, 0);
}
}
[RPC]
public void RemovePlayer(NetworkPlayer id)
{
Player temp = new Player();
foreach(Player pl in PlayerList)
{
if(pl.OnlinePlayer == id)
{
temp = pl;
}
}
if(temp != null)
{
PlayerList.Remove(temp);
}
}
[RPC]
public void LoadLevel()
{
MatchStarted = true;
Application.LoadLevel(1);
}
void OnLevelWasLoaded(int level)
{
if(MatchStarted == true)
SpawnPoints = LevelManager.Ins.SpawnPoints;
}
void OnGUI()
{
if(MatchStarted == true)
{
if(GUI.Button (new Rect(0,0,50,20),"Spawn"))
{
MyPlayer.Manager.networkView.RPC("Spawn",RPCMode.All);
int SpawnIndex = Random.Range(0,SpawnPoints.Count - 1);
MyPlayer.Manager.FirstPerson.position = SpawnPoints[SpawnIndex].position;
MyPlayer.Manager.FirstPerson.rotation = SpawnPoints[SpawnIndex].rotation;
}
}
}
}
[System.Serializable]
public class Player{
public string PlayerName;
public NetworkPlayer OnlinePlayer;
public float Health = 100;
public UserPlayer Manager;
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class LevelManager : MonoBehaviour {
public static LevelManager Ins;
public static List<Transform> SpawnPoints = new List<Transform>();
// Use this for initialization
void Start () {
Ins = this;
}
// Update is called once per frame
void Update () {
}
}
Thanks