Search Unity

player list and local authority

Discussion in 'Multiplayer' started by Resilo, Aug 11, 2017.

  1. Resilo

    Resilo

    Joined:
    Dec 8, 2016
    Posts:
    139
    ok so far i have a script on the local player that adds the username to a synclist.

    i have created an object with a script to collect all the usernames on it called playerlist
    problem is a networkspawn cannot be called on a monobehaviour and i need that object to be
    spawned as soon as the server starts


    here is the script that starts both client and player now i would do a network spawn just below when the server starts problem is i cant do that because it is not a network behavior and cannot be one otherwise it just gets disabled on start

    how can i get the server to to spawn the object after it starts

    any ideas are highly appreciated thanks.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine.Networking;
    4. using UnityEngine;
    5. using Unitycoding.LoginSystem;
    6.  
    7. public class server : MonoBehaviour {
    8.     public GameObject loginsystem;
    9.     public string username;
    10.     public GameObject playerlist;
    11.     public SyncListString players = new SyncListString();
    12.     void login()
    13.     {
    14.         if (username == "Admin")
    15.         {
    16.             NetworkManager.singleton.networkPort = 7777;
    17.             NetworkManager.singleton.networkAddress = "192.168.0,.139";
    18.             NetworkLobbyManager.singleton.StartServer();
    19.  
    20.            
    21.         }
    22.         if (username != "Admin")
    23.         {
    24.             NetworkManager.singleton.networkPort = 7777;
    25.             NetworkManager.singleton.networkAddress = "thereignofvilgramon.ddns.net";
    26.             NetworkLobbyManager.singleton.StartClient();
    27.  
    28.         }
    29.  
    30.     }
    31.  
    32.  
    33.  
    34.     // Use this for initialization
    35.     void Start () {
    36.         loginsystem = GameObject.Find("LoginSystem");
    37.         username = loginsystem.GetComponent<LoginSystem>().user;
    38.         login();
    39.     }
    40.    
    41.     // Update is called once per frame
    42.     void Update () {
    43.        
    44.     }
    45. }
    46.