Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

NetworkServer.UnSpawn is not working

Discussion in 'Connected Games' started by FrostyPixelsGames, Oct 11, 2018.

  1. FrostyPixelsGames

    FrostyPixelsGames

    Joined:
    Apr 9, 2018
    Posts:
    1
    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:
    4,395
    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