Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  5. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    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:
    3,954
    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