Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Daniel80012345 · Oct 10, 2017 at 12:12 PM · spritenetworkflip

Network flip

What is wrong with the flip?

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking;

public class Player : NetworkBehaviour {

 private Rigidbody2D _MyRigidbdoy;

 private float _SpeedMove = 5;

 public static bool _FacingRight;

 public GameObject _BulletPrefab;

 public Transform _BulletSpawn;

 // Use this for initialization
 void Start () {

     _MyRigidbdoy = GetComponent<Rigidbody2D> ();

     _FacingRight = true;
     
 }
     
 
 // Update is called once per frame
 void FixedUpdate () {

     if (!isLocalPlayer) {

         return;


     }
     
     float _Horizontal = Input.GetAxis ("Horizontal");

     HandleMovement (_Horizontal);
     CmdFlip (_Horizontal);

     if (Input.GetKeyDown (KeyCode.Space)) {

         CmdFire ();

     }

 }

 void HandleMovement(float _Horizontal){

     _MyRigidbdoy.velocity = new Vector2 (_Horizontal * _SpeedMove, _MyRigidbdoy.velocity.y);

 }

 [Command]
 void CmdFlip(float _Horizontal){

         RpcFlip (_Horizontal);

 }


 [ClientRpc]
  void RpcFlip(float _Horizontal){

     if (_Horizontal > 0 && !_FacingRight || _Horizontal < 0 && _FacingRight) {

         _FacingRight = !_FacingRight;

         Vector3 _TheScale = transform.localScale;

         _TheScale.x *= -1;

         transform.localScale = _TheScale;



     }


 }



 [Command]
 void CmdFire(){

     var _Bullet = (GameObject)Instantiate(
         _BulletPrefab,
         _BulletSpawn.position,
         _BulletSpawn.rotation);

     if (_FacingRight)
         _Bullet.GetComponent<Rigidbody2D> ().velocity = _Bullet.transform.right * 6;
     else
         _Bullet.GetComponent<Rigidbody2D> ().velocity = _Bullet.transform.right * -6;
     


     NetworkServer.Spawn (_Bullet);

     Destroy(_Bullet, 2.0f);        

 }
     

 public override void OnStartLocalPlayer()
 {

     GetComponent<SpriteRenderer> ().color = Color.red;
 
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

163 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Flipping a sprite with an attached gameobject 0 Answers

How do i get my character to move 3 Answers

How can I rotate a Sprite with the mouse? Like terraria or Starbound 0 Answers

Flip sprite sync Network problem 0 Answers

2D Multiplayer Character Flip 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges