- Home /
Question by
caseymac · Mar 13, 2016 at 12:01 AM ·
c#networkingtransformnetworklocalscale
Syncing localScale
How do you sync players localScale? I've been messing around with syncvars and [command]s but it either doesn't work at all or only works on the host.
my latest attempt flips it on the server, but nowhere else
[Command]
void CmdFlip(int dir){
transform.localScale = new Vector3 (dir, 1, 1);
}
and this is when im calling it
if (Input.GetKey (KeyCode.A)) {
transform.localScale = new Vector3 (-1, 1, 1); // flips it on client maybe idk this shits wack
CmdFlip(-1);
} else if (Input.GetKey (KeyCode.D)) {
transform.localScale = new Vector3 (1, 1, 1); // flips it on client maybe idk this shits wack
CmdFlip(1);
}
Comment
@caseymac You should check out this tutorial, you would use the same principle as with movement but replace transform.position with transform.localScale :)
I was tried this and it doesn´t nothing :(
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class SyncScale : NetworkBehaviour {
[SyncVar] private Vector3 syncScale;
[SerializeField] Transform myTransform;
[SerializeField] float lerpRate = 15;
// Update is called once per frame
void FixedUpdate () {
TransmitScale ();
LerpScale ();
}
void LerpScale(){
if (isLocalPlayer) {
myTransform.localScale = Vector3.Lerp (myTransform.localScale, syncScale, Time.deltaTime * lerpRate);
}
}
[Command]
void CmdProvideScaleToServer(Vector3 scale){
syncScale = scale;
}
[ClientCallback]
void TransmitScale(){
if (isLocalPlayer) {
CmdProvideScaleToServer (myTransform.localScale);
}
}
}
Your answer
Follow this Question
Related Questions
Networking Sync SetActive Not Working 0 Answers
Photon Networking: LocalScale transform doesn't work 1 Answer
remove spawned object from my networkView when timeScale = 0 0 Answers
How do i animate threw network 1 Answer
Multiple Cars not working 1 Answer