- Home /
Editing a Player's Scale Over the Network
Hey guys,
I'm somewhat new to network programming, so this question might be really obvious, but I can't seem to find an answer anywhere.
I'm making a 2D multiplayer game, and I want it so that when a player goes left or right, it changes the scale so that the character looks to be facing left or right.
The only problem is, while I can get the host's direction to update on the client, I cannot get the client's direction to update on the host's screen. Could you tell me what I'm doing wrong?
Here's the code I'm using:
[SyncVar]
private bool facingLeft;
private Vector2 defaultScale;
void Start() {
defaultScale = transform.localScale;
if (!isLocalPlayer) {
return;
}
anim = GetComponent<Animator>();
}
void Update() {
Facing();
if (!isLocalPlayer) {
return;
}
Movement();
}
void Movement() {
if (Input.GetButton("Forward") || Input.GetButton("Back") || Input.GetButton("Left") || Input.GetButton("Right")) {
anim.SetBool("isWalking", true);
} else {
anim.SetBool("isWalking", false);
}
if (Input.GetButton("Forward")) {
transform.Translate(new Vector2(0,1 * movementSpeed * Time.deltaTime));
} else if (Input.GetButton("Back")) {
transform.Translate(new Vector2(0,-1 * movementSpeed * Time.deltaTime));
}
if (Input.GetButton("Right")) {
transform.Translate(new Vector2(1 * movementSpeed * Time.deltaTime, 0));
facingLeft = false;
} else if (Input.GetButton("Left")) {
transform.Translate(new Vector2(-1 * movementSpeed * Time.deltaTime, 0));
facingLeft = true;
}
}
void Facing() {
if (facingLeft) {
transform.localScale = new Vector2(-defaultScale.x, defaultScale.y);
} else if (!facingLeft) {
transform.localScale = new Vector2(defaultScale.x, defaultScale.y);
}
Thanks!
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Online Player Position 1 Answer
How Push Players on Network 0 Answers
[Networking]How to call a command function from a UI element(a button) 2 Answers
[uLink] Instantiation 0 Answers