Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Objects not spawning with tags for local players.

Discussion in 'Multiplayer' started by wwm0nkey, Mar 15, 2016.

  1. wwm0nkey

    wwm0nkey

    Joined:
    Jul 7, 2015
    Posts:
    42
    So here is how I am currently spawning bullets (coins actually) in game
    Code (CSharp):
    1.     [Command]
    2.     void CmdDoFire() {
    3.          GameObject bullet = (GameObject)Instantiate(
    4.          CoinPrefab,
    5.          GameObject.Find(transform.name +" Invest").transform.position,
    6.          Quaternion.identity);
    7.          bullet.gameObject.tag = transform.name + " Coin";
    8.          NetworkServer.Spawn(bullet);
    9.  
    10.  
    11.     }
    So on the host he will see the tag being the playername + Coin. I did this to only give the players over the coins that they spawn, however the tags do not change on the local player so I can not add them to an array or do anything really which makes doing the rest of this project hard going forward.

    Does anyone know a quick solution to this issue?
     
  2. wwm0nkey

    wwm0nkey

    Joined:
    Jul 7, 2015
    Posts:
    42
    UPDATE: Okay so I have some of it working now but I have a problem where 2 coins spawn rather than one. I made a RPC that runs the code and then that goes through the command.

    Here is how it is currently set up:
    Code (CSharp):
    1.  [Command]
    2.     void CmdDoFire() {
    3.  
    4.         RpcDoFire();
    5.     }
    6.  
    7.         [ClientRpc]
    8.         public void RpcDoFire() {
    9.  
    10.             bullet = (GameObject)Instantiate(
    11.             CoinPrefab,
    12.             GameObject.Find(transform.name + " Invest").transform.position,
    13.             Quaternion.identity);
    14.             bullet.gameObject.tag = transform.name + " Coin";
    15.             NetworkServer.Spawn(bullet);
    16.     }
    So how would I go about making sure it doesn't spawn 2 coins all the time?
     
  3. Oshroth

    Oshroth

    Joined:
    Apr 28, 2014
    Posts:
    99
    You aren't spawning it correctly. You'll have 2 copies of the coin on the client, one with the wrong tag but networked correctly, the other with the tag you want but not networked.

    I'm not sure what you are trying to do.

    If you are trying to have players control over their objects, then use client authority to give it to them instead of a hacky tag system.
     
  4. wwm0nkey

    wwm0nkey

    Joined:
    Jul 7, 2015
    Posts:
    42
    What I am trying to do is have 5 people in a room with 4 of them playing and one being the host/admin. At the start of the round it should spawn 20 coins for each player besides the admin and they decide weather to keep or donate the coins. When they are done moving their coins a trigger box should spawn on the area and move the coin out of the map to another trigger box to be counted by the server. I was using the tag system to make sure all objects are added into the array with their player name, though I guess I could just add them to the array as they spawn?