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. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Unity Multiplayer Projectile Instantiation / Closed

Discussion in 'Multiplayer' started by Loppy, Jun 25, 2015.

  1. Loppy

    Loppy

    Joined:
    Jun 19, 2015
    Posts:
    11
    Im having a problem instantiating projectiles in Unity multiplayer. Im basicly instantiating a prefab and change its values before it gets instantiatet, all clients just get the projectile with the value of the original prefab, it doesnt change. Is there a better way to instantiate projectiles in multiplayer? Im having a skill system which lets the player change each aspect of the skill ingame so i think i have to change a prefab object because i dont want to pre build every possible projectile.
    Sry for bad english :)
     
  2. SuperNeon

    SuperNeon

    Joined:
    Mar 16, 2014
    Posts:
    85
    Hi Loppy,

    You need to add the attribute SyncVar on the properties. It will be replicated on the clients automatically :)
    For exemple:
    Code (CSharp):
    1. public class Bullet
    2. {
    3.      [SyncVar]
    4.      public float damage = 5f;
    5. }
    When you will spawn a Bullet from the server and change the damage value. The clients will receive the correct value.
     
  3. Loppy

    Loppy

    Joined:
    Jun 19, 2015
    Posts:
    11
    I tried something like this :

    public class UseSkills {
    [SyncVar]public Gameobject Projectile;
    }
    public class UseProjectile {
    public skill = gameObject.GetComponent<UseSkills>();
    [Command]
    public void cmdProjectileSkill(){
    GameObject clone = Instantiate(skill.Projectile);
    NetworkServer.Spawn(clone);
    }
    }

    doesnt get synced
    EDIT: ok i think i cant sync Gameobjects so im looking for a new solution thx!
     
    Last edited: Jun 26, 2015