Search Unity

NetworkServer.UnSpawn is not working

Discussion in 'Multiplayer' started by MadLambGames, Oct 11, 2018.

  1. MadLambGames

    MadLambGames

    Joined:
    Apr 9, 2018
    Posts:
    3
    Hi, first of all let me tell you NetworkServer.Spawn(); is working, but i cant get NetworkServer.UnSpawn(); to work I'm pretty sure there is something missing in the code and I'd like to know what is it, here's the code
    but i have to tell you that the object has local player authority checked

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. using UnityEngine.Networking;
    6. public class spawnGroundCrown : NetworkBehaviour{
    7.  
    8.     public GameObject crownOnGroundPrefab;
    9.  
    10.     public GameObject instCrown;
    11.     public bool crownOnGroundIsSpawned = false;
    12.  
    13.    // Use this for initialization
    14.     void Start () {
    15.        
    16.     }
    17.    
    18.     // Update is called once per frame
    19.     void Update () {
    20.        
    21.    
    22.         if(crownOnGroundIsSpawned == false)
    23.  
    24.         {
    25.             crownOnGroundIsSpawned = true;
    26.  
    27.             CmdShowGroundCrown();
    28.         }
    29.  
    30.         if (crownOnGroundIsSpawned == true && Input.GetKey(KeyCode.Space))
    31.  
    32.         {
    33.             CmdUnshowGroundCrown();
    34.         }
    35.  
    36.     }
    37.  
    38.     [Command]
    39.     public void CmdShowGroundCrown()
    40.  
    41.     {
    42.         instCrown = (GameObject)Instantiate(crownOnGroundPrefab, crownOnGroundPrefab.transform.position, crownOnGroundPrefab.transform.rotation);
    43.  
    44.         NetworkServer.Spawn(instCrown);
    45.     }
    46.  
    47.     [Command]
    48.     public void CmdUnshowGroundCrown()
    49.  
    50.     {
    51.         NetworkServer.UnSpawn(instCrown);
    52.     }
    53. }
    54.  
    thank you, I hope you understand the code
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    This code doesn't make much sense to me. Why use NetworkServer.Unspawn instead of NetworkServer.Destroy? Your Update method is written so it will be run on the server and all clients, but it doesn't look like that is your intention.
     
    Last edited: Oct 13, 2018