Search Unity

How to handle object that have behavior depends on the local scene?

Discussion in 'Multiplayer' started by Go2ready, Jul 2, 2015.

  1. Go2ready

    Go2ready

    Joined:
    May 8, 2015
    Posts:
    29
    Hello all,

    I used to have a implementation that
    • All player objects in the scene are tagged as either Player, Friend, Enemy.
    • A auto firing weapon that will only fire to the object that marked as Enemy.
    It works well on single player.

    But as I want this to be multiplayer, I am wondering how to spawn such weapon over the all the clients, I can assume it will go crazy firing every one once spawned.

    Will making the server run the firing logic works? Do I have to change my implementation, instead of marking players as such, mark them using team number instead?

    Thanks, your help is appreciated!
     
  2. Necromantic

    Necromantic

    Joined:
    Feb 11, 2013
    Posts:
    116
    You can use a command to have the server fire the logic and can provide what it should fire at as a parameter as long as it has a NetworkIdentity.

    Not quite sure on the details of what you want.
     
  3. Go2ready

    Go2ready

    Joined:
    May 8, 2015
    Posts:
    29
    Hello Necromantic,

    Thanks for replying! I want to build a PvP games where players are able to spawn some auto firing weapon that will fire at their enemy(My current logic of that weapon is checking whether the target is tagged as Enemy when it attemp to fire).

    But as you can see this tag is quite local to client's scene. So as you suggest, when such weapon is spawned by one player, I should let server fire by sending a command and pass all enemy's netId, and server will check their netid before firing in my weapon's logic?

    Please correct me if I misunderstood something here :D

    Thanks again!