Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Aug 09, 2013 at 10:29 AM by CHPedersen for the following reason:

Write-my-code

avatar image
0
Question by ErikJG · Aug 09, 2013 at 10:26 AM · error-handling

How to sove this script error?

The error for this script is :Assets/Scripts/Multiplayer Manager.cs(283,16): error CS0118: MPPlayer.PlayerManager' is a field' but a `type' was expected

Please can some one quickly edit the script. Make sure it works. and then edit it on here heres the script:

using UnityEngine; using System.Collections; using System.Collections.Generic;

public class MultiplayerManager : MonoBehaviour {

 public static MultiplayerManager instance;
 
 public GameObject PlayerManagerPrefab;
 
 public string PlayerName;
 
 private string ServerName = "";
 
 private string ServerPassword = "";
 
 private int MaximumPlayers = 10;
 
 public List <MPPlayer> PlayerList = new List<MPPlayer>();
 public List <MapSettings> MapList = new List<MapSettings>();

 public MapSettings CurrentMap = null;
 
 public int oldprefix;
 
 public bool IsMatchStarted = false;
 
 public MPPlayer MyPlayer;
     
 public bool MatchLoaded;
 
 public GameObject[] Spawnpoints;
 
 void Start() {
     
     instance = this;
     PlayerName = PlayerPrefs.GetString("PlayerName");
     
     CurrentMap = MapList[0];
     
     DontDestroyOnLoad(gameObject);
 }
 
 void FixedUpdate() {
 
     instance = this;
 
 }
 
 public void StartServer(string servername, string serverpassword, int maxusers) {
     
     ServerName = servername;
     
     ServerPassword = serverpassword;
     
     MaximumPlayers = maxusers;
     
     Network.InitializeServer(MaximumPlayers, 2550, false);
     
     //Network.InitializeSecurity();
     
     MasterServer.RegisterHost("Free For All", ServerName, "");
     
 }
 
 void OnServerInitialized() {
     
     Server_PlayerJoinRequest(PlayerName, Network.player);
     
 }
 
 void OnConnectedToServer() {
     
     networkView.RPC("Server_PlayerJoinRequest", RPCMode.Server, PlayerName, Network.player);
     
 }
 
 void OnPlayerDisconnected(NetworkPlayer id) {
 
     networkView.RPC("Client_RemovePlayer", RPCMode.All, id);
 
 }
 
 void OnPlayerConnected(NetworkPlayer player) {
     
     foreach(MPPlayer pl in PlayerList) {
         
     networkView.RPC("Client_AddPlayerToList", player, pl.PlayerName, pl.PlayerNetwork);
             
     }
     
     networkView.RPC("Client_GetMultiplayerMatchSettings", player, CurrentMap.MapName, "", "");
         
 }
 
 void OnDisconnectedFromServer() {
 
     PlayerList.Clear();
 
 }
     
 [RPC]
 
 void Server_PlayerJoinRequest(string playername, NetworkPlayer view) {
     
     networkView.RPC("Client_AddPlayerToList", RPCMode.All, playername, view);
     
 }
 
 [RPC]
 
 void Client_AddPlayerToList(string playername, NetworkPlayer view) {
     
     MPPlayer tempplayer = new MPPlayer();
     tempplayer.PlayerName = playername;
     tempplayer.PlayerNetwork = view;
     PlayerList.Add(tempplayer);
     if(Network.player == view) {
     
         MyPlayer = tempplayer;
         GameObject play = Network.Instantiate(PlayerManagerPrefab, Vector3.zero, Quaternion.identity, 5) as GameObject;
         
     }
     
 }
 
 [RPC]
 
 void Client_RemovePlayer(NetworkPlayer view) {
   
     MPPlayer temppl = null;
     foreach(MPPlayer pl in PlayerList ) {
     
         if(pl.PlayerNetwork == view) {
         
             temppl = pl;
         
         }
         
         if(temppl != null) {
         
             PlayerList.Remove(temppl);
         
         }
     
     }
     
 }
 
 [RPC]
 
 void Client_GetMultiplayerMatchSettings(string map, string mode, string others) {
 
     CurrentMap = GetMap(map);
 
 }
 
 public MapSettings GetMap(string name) {
 
     MapSettings get = null;
     
     foreach(MapSettings st in MapList) {
     
         if(st.MapName == name) {
         
             get = st;
             break;
         
         }
     
     }
     
     return get;
 
 }
 
 [RPC]
 
 void Client_LoadMultiplayerMap(string map, int prefix) {
 
     //Network.SetLevelPrefix(prefix);
     Application.LoadLevel(map);
 
 }
 
 void OnGUI()
 {
    if(!MyPlayer.PlayerIsAlive && IsMatchStarted)
      SpawnMenu();
 }
 
 [RPC]
 
 void Server_SpawnPlayer(NetworkPlayer player) {
 
    int numberspawn = Random.Range(0, Spawnpoints.Length - 1);
    networkView.RPC("Client_SpawnPlayer", RPCMode.All, player, Spawnpoints[numberspawn].transform.position + new Vector3(0, 2, 0), Spawnpoints[numberspawn].transform.rotation);
 
 }
 
 [RPC]
 
 void Client_SpawnPlayer(NetworkPlayer player, Vector3 position, Quaternion rotation) {
 
     if(player == MyPlayer.PlayerNetwork) {
     
         MultiplayerManager.GetMPPlayer(player).PlayerIsAlive = true;
         MultiplayerManager.GetMPPlayer(player).PlayerHealth = 100;
     
         MyPlayer.PlayerManager.ControllerTransform.position = position;
         MyPlayer.PlayerManager.ControllerTransform.rotation = rotation;
         MyPlayer.PlayerManager.networkView.RPC("Client_PlayerAlive", RPCMode.All);

     }
     else {
     
         
     
     }
 
 }
 
 [RPC]
 
   void OnLevelWasLoaded() {
 
    if(Application.loadedLevelName == CurrentMap.MapLoadName && Network.isServer) {
    
      MatchLoaded = true;
      Spawnpoints = GameObject.FindGameObjectsWithTag("spawnpoint");
      networkView.RPC("Client_ServerLoaded", RPCMode.AllBuffered, IsMatchStarted);
      
    }
    
 }
 
 [RPC]
 
 void Client_ServerLoaded(bool started) {
 
     MatchLoaded = true;
     
     IsMatchStarted = started;
 
 }
 
 public static MPPlayer GetMPPlayer(NetworkPlayer player) {
 
     foreach(MPPlayer play in MultiplayerManager.instance.PlayerList) {
     
         if(play.PlayerNetwork == player) {
         
             return play;
         
         }
     
     }
 
     return null;
 
 }
 
  void SpawnMenu()
 {
    if(GUI.Button(new Rect(5, Screen.height -40, 250, 35),"Spawn"))
    {
      if(Network.isServer)
       Server_SpawnPlayer(Network.player);
      else
       networkView.RPC("Server_SpawnPlayer", RPCMode.Server, Network.player);
    }
 }
 

}

[System.Serializable] public class MPPlayer {

 public string PlayerName = "";
 
 public NetworkPlayer PlayerNetwork;
 
 public PlayerManager PlayerManager;
 
 public int PlayerHealth = 100;
 
 public bool PlayerIsAlive;
 
 public int PlayerKills;
 
 public int PlayerDeaths;
 

}

[System.Serializable] public class MapSettings {

 public string MapName;
 public string MapLoadName;
 public Texture MapLoadTexture;
 

}

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CHPedersen · Aug 09, 2013 at 10:29 AM 0
Share

That's not how Unity Answers works, sorry. :-/ We help you solve your issues so you understand how to solve similar issues yourself later on. We do not solve your issues for you and just return working code. That would be working for you for free, and like the Joker once told a bunch of mob bosses: If you're good at something... never do it for free. :)

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Double Clicking Errors/Output In The Console Triggered By External Assemblies 0 Answers

Free Service to log my games error logs to 2 Answers

I need help with this script, where are the errors? 2 Answers

Assembly with name 'Unity.XR.ARKit.FaceTracking' already exists (Packages/com.unity.xr.arkit/Runtime/FaceTracking/Unity.XR.ARKit.FaceTracking.asmdef) 0 Answers

Is there an easy way to pop-up error messages 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges