• 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 /
avatar image
0
Question by D3m0nE · Mar 16, 2013 at 06:29 PM · multiplayernetworkrpc

MultiPlayer People Cant See Each Others

Hello Everyone i got problem in my multiplayer game

that people cant see each other

in the Multiplayer Script [In Scene 1]

     void OnPlayerConnected(NetworkPlayer networkPlayer)
     {
     int playerCount = 0;
     Debug.Log("Player " + playerCount++ + " connected from " + networkPlayer.ipAddress + ":" + networkPlayer.port);
     networkView.RPC("ShowTheSpawnMenuOnJoin", networkPlayer,serverName,numberOfPlayers,"Yes");
     }
 
 
     [RPC]
     void ShowTheSpawnMenuOnJoin(string servername, int maxplayers,string ShowIt){
     
     Application.LoadLevel("WildZone");
     Debug.Log("I Joined The WildZone Map");    
     SpawnScript.serverName = servername;
     SpawnScript.MaxPlayers = maxplayers;
     SpawnScript.justConnectedToServer = true;
     }
 

And My Spawn Script attached into gameobject called SpawnManager in the [scene 2]:

 using UnityEngine;
 using System.Collections;
 
 /// <summary>
 /// This script is attached to the SpawnManager and it allows
 /// the player to spawn into the multiplayer game.
 /// </summary>
 
 
 public class SpawnScript : MonoBehaviour {
     
     //Variables Start___________________________________
     
     //Used to determine if the palyer needs to spawn into
     //the game.
     
     public static bool justConnectedToServer = false;    
     public static string serverName;
     public static int MaxPlayers;
     
     //Used to determine which team the player is on.
     
     public bool amIOnTheRedTeam = false;
     
     public bool amIOnTheBlueTeam = false;
 
     //Used to define the JoinTeamWindow.
     
     private Rect joinTeamRect;
     
     private string joinTeamWindowTitle = "Team Selection";
     
     private int joinTeamWindowWidth = 330;
     
     private int joinTeamWindowHeight = 100;
     
     private int joinTeamLeftIndent;
     
     private int joinTeamTopIndent;
     
     private int buttonHeight = 40;
     
     
     //The Player prefabs are connected to these in the 
     //inspector
     
     public Transform redTeamPlayer;
     
     public Transform blueTeamPlayer;
     
     private int redTeamGroup = 0;
     
     private int blueTeamGroup = 1;
     
     
     //Used to capture spawn points.
     
     private GameObject[] redSpawnPoints;
     
     private GameObject[] blueSpawnPoints;
     
     
     //Variables End_____________________________________
     
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     
     
     void OnConnectedToServer ()
     {
         justConnectedToServer = true;    
     }
     
     
     
     void JoinTeamWindow (int windowID)
     {
         //If the player clicks on the Join Red Team button then
         //assign them to the red team and spawn them into the game.
         
         if(GUILayout.Button("Join red Team", GUILayout.Height(buttonHeight)))
         {
             amIOnTheRedTeam = true;
             
             justConnectedToServer = false;
             
             SpawnRedTeamPlayer();
         }
         
         
         //If the player clicks on the Join Blue Team button then
         //assign them to the blue team and spawn them into the game.
         
         if(GUILayout.Button("Join blue Team", GUILayout.Height(buttonHeight)))
         {
             amIOnTheBlueTeam = true;
             
             justConnectedToServer = false;
             
             SpawnBlueTeamPlayer();
         }
     }
     
     
     void OnGUI()
     {
         //If the player has just connected to the server then draw the 
         //Join Team window.
         
         if(justConnectedToServer == true)
         {
             joinTeamLeftIndent = Screen.width / 2 - joinTeamWindowWidth / 2;
             
             joinTeamTopIndent = Screen.height / 2 - joinTeamWindowHeight / 2;
             
             joinTeamRect = new Rect(joinTeamLeftIndent, joinTeamTopIndent,
                                     joinTeamWindowWidth, joinTeamWindowHeight);
             
             joinTeamRect = GUILayout.Window(0, joinTeamRect, JoinTeamWindow,
                                             joinTeamWindowTitle);
         }
     }
     
     
     void SpawnRedTeamPlayer ()
     {
         //Find all red spawn points and place a reference to them in the array
         //redSpawnPoints.
         
         redSpawnPoints = GameObject.FindGameObjectsWithTag("SpawnRedTeam");
         
         
         //Randomly select one of those spawn points.
         
         GameObject randomRedSpawn = redSpawnPoints[Random.Range(0, redSpawnPoints.Length)];
         
         
         //Instantiate the player at the randomly selected spawn point.
         
         Network.Instantiate(redTeamPlayer, randomRedSpawn.transform.position,
                             randomRedSpawn.transform.rotation, redTeamGroup);
     }
     
     
     
     void SpawnBlueTeamPlayer ()
     {
         //Find all blue spawn points and place a reference to them in the array
         //blueSpawnPoints.
         
         blueSpawnPoints = GameObject.FindGameObjectsWithTag("SpawnBlueTeam");
         
         
         //Randomly select one of those spawn points.
         
         GameObject randomBlueSpawn = blueSpawnPoints[Random.Range(0, blueSpawnPoints.Length)];
         
         
         //Instantiate the player at the randomly selected spawn point.
         
         Network.Instantiate(blueTeamPlayer, randomBlueSpawn.transform.position,
                             randomBlueSpawn.transform.rotation, blueTeamGroup);
     }
     
     
     [RPC]
     void ShowTheSpawnMenuOnJoin(string servername, int maxplayers,string ShowIt){
     serverName = servername;
     MaxPlayers = maxplayers;
     justConnectedToServer = true;
     }
     
     
     
 }
 
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 Benproductions1 · Mar 27, 2013 at 03:56 AM 0
Share

What too much to read through, could you summarise your multiplayer logic?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

11 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

Related Questions

When to use OnSerializeNetworkView and RPC's 1 Answer

Multiplayer - Selected character to Network.guid? 0 Answers

Problem with RPC attribute. 0 Answers

Does the position change need state synchronization? 2 Answers

get return on networkView.RPC 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges