- Home /
Question by
$$anonymous$$ · Feb 26, 2017 at 10:23 PM ·
2dnetworkingnetworkview
String only syncing on host with client, but not client with host
I use this script to change sprite sheet that is used to render the player, but it only syncs through the host, but not the normal client. Please help me with this issue.
This is my code:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class ReSkinAnimation : NetworkBehaviour {
[SyncVar]
public string spriteSheetName;
// Update is called once per frame
void LateUpdate () {
var subSprites = Resources.LoadAll<Sprite>("Characters/" + spriteSheetName);
foreach (var renderer in GetComponentsInChildren<SpriteRenderer>())
{
string spriteName = renderer.sprite.name;
var newSprite = Array.Find(subSprites, item => item.name == spriteName);
if (newSprite)
renderer.sprite = newSprite;
}
}
void OnGUI()
{
if (isLocalPlayer)
spriteSheetName = GUI.TextField(new Rect(25, Screen.height - 40, 100, 30), spriteSheetName);
}
public static implicit operator ReSkinAnimation(string v)
{
throw new NotImplementedException();
}
}
Comment