Unet multiplayer Client Host confusion
Hi everyone . Currently working on multiplayer based CCG game.Using Host and client type interaction. And i am really confused about how Host and client relations go in UNET. Asking those questions because i'm trying to make several objects under control of my player and others under control of the other and using SpawnWithClientAuthority for that. And besides all that objects themselves like Deck should able to spawn objects for me.That was first issue When i send [Command] to the server and Rpc back to syncronize the changes it ignores either Server or client.I have got it finally working somehow but now really confused about how things work Here is an example:
using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using TMPro;
public class CardDistributor : NetworkBehaviour
{
public enum side
{
Soviet,
German
}
public side Side;
public Sprite SovietBack, GermanBack;
public SpriteRenderer DeckBack;
public TMP_Text DeckCount;
[SyncVar]
public int CurrentDeckCount;
[SyncVar]
public string SyncronizeSides;
void Start()
{
if (hasAuthority)
{
FirstDisribution[] possibleDistributionScripts = FindObjectsOfType<FirstDisribution>();
foreach(FirstDisribution dis in possibleDistributionScripts)
{
if(dis.hasAuthority)
{
BulkDistributionScript = dis;
dis.Deck = gameObject.GetComponent<CardDistributor>();
}
}
myProfile = FindObjectOfType<DemoProfile>();
Side = (side)Enum.Parse(typeof(side),myProfile.MySide.ToString());
CmdSetSidesSynch(Side.ToString());
SyncronizeSides = Side.ToString();
}
else
{
DeckBack.transform.localRotation = Quaternion.Euler(0, 0, 180);
DeckCount.transform.localRotation = Quaternion.Euler(0, 0, 180);
}
if (SyncronizeSides == "Soviet")
{
DeckBack.sprite = SovietBack;
}
else
{
DeckBack.sprite = GermanBack;
}
}
[Command]
public void CmdSetSidesSynch(string side)
{
SyncronizeSides = side;
if (SyncronizeSides == "Soviet")
{
DeckBack.sprite = SovietBack;
}
else
{
DeckBack.sprite = GermanBack;
}
RpcSyncSides(side);
}
[ClientRpc]
public void RpcSyncSides(string side)
{
SyncronizeSides = side;
}
And i know the code is a mess and i will rewrite it. Besides i have removed non issue related parts .All i need to know how Rpc, Command and SyncVar works on non player objects with authority with Host-Client setup. I really need help on this one