- Home /
how do i network sync scaling of character?
I tried using this script to make the player larger and smaller when pressing U or J wich kinda works. Im new to networking and unity for that matter...
using UnityEngine; using UnityEngine.Networking; using System.Collections;
public class SinglepalyerSizeChanger : NetworkBehaviour { public GameObject player; public GameObject model;
public float growvalue = 0.2f;
public float growvalue2 = 0.01f;
void Update()
{
if (isLocalPlayer)
{
Enlarge();
Dislarge();
return;
}
}
void Enlarge()
{
if (Input.GetKeyDown(KeyCode.U))
{
player.transform.localScale += new Vector3(growvalue, growvalue, growvalue);
}
}
void Dislarge()
{
if (Input.GetKeyDown(KeyCode.J))
{
player.transform.localScale += new Vector3(-growvalue, -growvalue, -growvalue);
}
}
}
But when using it on network the second player (or first if the second is growing/shrinking) sees the first guy floating in the air. The model doesnt grow. Anyone have any idea about how i could do that?
Answer by fafase · Jan 09, 2017 at 10:55 AM
[SyncVar(hook = "OnSetScale")] private Vector3 scale;
[Command]
public void SetScale(Vector3 vec)
{
this.scale = vec; // This is just to trigger the call to the OnSetScale while encapsulating.
}
private void OnSetScale(Vector3 vec){
this.scale = vec;
this.transform.localScale = vec;
}
Your answer
Follow this Question
Related Questions
How do I find the player GameObject of the local player? 2 Answers
Child of a player not syncing position with network? 0 Answers
Animation over network using rpcs 0 Answers
Unity Multiplayer - Instantiate prefab 1 Answer
How to make just a simple server to save arrays and vars for a multiplayer? 0 Answers