Question by
lm2malicl · Feb 02, 2018 at 04:52 AM ·
networkingspritespriterenderer
Flipping a sprite on a network
Hello all,
I have been beating my head against a wall for about 2 weeks on this. I am trying to get a sprite to flip over UNET (unity networking) the characters move/jump using a rigidbody2d just fine, but the sprites only flip locally. I have tried every combination of Cmd and Rpc I can think of to no avail. Any help would be greatly appreciated. Bellow is the relevant parts of my code.
public void MovePlayer(float _move,bool _jumping,bool _crouched){
//move only if the player is grounded or aircontrol is enabled
if(isGrounded || airControl){
//reduce speed if crouched
if(_crouched){
_move = _move*crouchSpeed;
}
//move the character
rb2D.velocity = new Vector2(_move*maxSpeed,rb2D.velocity.y);
//jump if appropriate
if(_jumping && currentNumberOfJumps<maxNumberOfJumps){
Jump();
}
//flip the character if neccessary
if((_move>0&&!facingRight)||(_move<0&&facingRight)){
CmdFlipSprite();
}
}
}
[Command]
public void CmdFlipSprite (){
facingRight = !facingRight;
if (facingRight) {
spriteRenderer.flipX = false;
} else {
spriteRenderer.flipX = true;
}
}
Comment
Your answer
Follow this Question
Related Questions
Change sprite onTriggerEnter2D 0 Answers
My sprite renderer loads the wrong sprite on a new scene 0 Answers
Sprite didn't change more than once 0 Answers
How can I cast shadows onto sprites? 0 Answers
MissingFieldException: UnityEngine.SpriteRenderer.sprite 0 Answers