Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Set Non Player Variables

Discussion in 'Connected Games' started by Miggi124, May 1, 2019.

  1. Miggi124

    Miggi124

    Joined:
    Jul 31, 2017
    Posts:
    69
    Hi all,

    I'm kinda new to networking, and would like to apologise if this question is kinda obvious - so... yeah. Thanks in advance if you have a solution :)

    Anyway, I'm working on a simple project that requires the water level of an area to rise and fall, and it's essential for this to be networked (or at least so that it's at the same level on everybody's game). However, I'm only really used to syncing player variables, and I'm not used to doing anything like this.

    Would I have to spawn an AI, and sync it's variables that way?

    Thanks for any help,

    Miggi124
     
  2. Whippets

    Whippets

    Joined:
    Feb 28, 2013
    Posts:
    1,772
    That probably depends upon your choice of networking solution.
     
  3. g_a_p

    g_a_p

    Joined:
    Mar 16, 2015
    Posts:
    112
    Agree. For example in SmartFoxServer we have the so-called Room Variables. When updated, they are synchronized on all the clients connected to the same game "room".
     
  4. LukeDawn

    LukeDawn

    Joined:
    Nov 10, 2016
    Posts:
    319
    SmartFox server is pretty dope.
     
  5. Miggi124

    Miggi124

    Joined:
    Jul 31, 2017
    Posts:
    69
    Hi,

    Just to clarify, I'm thinking of using UNET or Photon Networking... would anyone have any ideas?
     
  6. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,170
    Don't use UNET, it's deprecated.

    Photon has a couple of options you can use, Room properties and RaiseEvent.
     
    Joe-Censored likes this.
  7. Miggi124

    Miggi124

    Joined:
    Jul 31, 2017
    Posts:
    69
    Hi
    ,

    Would you know of a good place to learn Photon newtorking? I'm pretty sure there are some tutorials but was wondering if Unity had any proper documentation or anything. Also, if possible, would you be able to provide some code (pseudo or not) that demonstrates how these functions work? If that's not possible, thanks for reading this anyway.

    Kind Regards,

    Miggi124
     
  8. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,170
    There's no Unity documentation for Photon PUN as it's a 3rd party product. But there are loads of tutorials available for it, a quick Google of 'Photon OUN Tutorial' will produce tons of results.

    I can't recommend any off hand as it's been a long while since I looked at them, and any that I used myself will be a bit out of date now.

    A lot of them will probably still be for Photon 1, but that's not really a problem because if you can't find one that targets Photo 2 you can follow the Photon 1 ones (using Photon 1 obviously), and once you've learnt the ropes you shouldn't find it too difficult to get to grips with Photon 2 yourself.
     
  9. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    5,452
    Whatever network solution you choose, the process for syncing player and non-player variables will either be identical or very similar. Generally you have one computer which is actually in charge of this variable (generally the sever or a master client) and you update the other clients either through a SyncVar or similar automatic variable syncing mechanism, or you send some form of RPC to all clients with the update.
     
  10. Miggi124

    Miggi124

    Joined:
    Jul 31, 2017
    Posts:
    69
    Hi,

    Thanks for the quick reply. So - in my game I have a floor that lowers down from the sky, and I was wondering if I should make it a prefab, and instantiate it in when the game starts, or simply have a server variable that dictates it's current position.

    If anyone could give their opinion, that would help. Also, for anyone else looking at this post, I'm going to post my progress and hopefully share my code later on.

    Kind Regards (and thanks for all the help :) )

    Miggi124