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 NITRONOME · Jul 26, 2017 at 02:08 PM · 2dnetworkingspritemultiplayersynchronization

How to Update Objects Sprite to the Network

Hey there. Im trying to make a 2D online game with "Move to mouse click position" style with player following camera. The movement itself works fine with the Network transform script on Player prefab. On the other hand i manage the moving with changing objects sprite for the angle object moves but the changes in the sprites doesnt apply to the server. so player sees other players moving without any sprite change. i am trying to fix this for 4 days. i read everything i can find but non of them worked.Can you guys please help me with this.

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

public class PlayerController : NetworkBehaviour {

 public float angle;
 public float ShipSpeed = 7.0f;
     public Vector3 localTarget;

 public Sprite a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,r,s,t,u,v,y,z,za,zb,zc,zd,ze,zf,zg,zh,zi; 

 public void FixedUpdate()
 { 
     if (isLocalPlayer) {
         Move ();
         ChangeSprite ();
     }
 }

 void Move(){
     if (Input.GetMouseButton (0)) {
         SelectTarget ();
         localTarget = Camera.main.ScreenToWorldPoint (Input.mousePosition);
         localTarget.z = 0;
     }
     transform.position = Vector3.MoveTowards (transform.position, localTarget, ShipSpeed);
 }
     void ChangeSprite(){
     angle = Mathf.Atan2 (localTarget.y - bulletSpawn.transform.position.y, localTarget.x - bulletSpawn.transform.position.x) * 180 / Mathf.PI;
     if (angle > -95.625f && angle <= -84.375f) {GetComponent<SpriteRenderer>().sprite = a;}
     if (angle > -84.375f && angle <= -73.125f) {GetComponent<SpriteRenderer>().sprite = b;}
     if (angle > -73.125f && angle <= -61.875f) {GetComponent<SpriteRenderer>().sprite = c;}
     if (angle > -61.875f && angle <= -50.625f) {GetComponent<SpriteRenderer>().sprite = d;}
     if (angle > -50.625f && angle <= -39.375f) {GetComponent<SpriteRenderer>().sprite = e;}
     if (angle > -39.375f && angle <= -28.125f) {GetComponent<SpriteRenderer>().sprite = f;}
     if (angle > -28.125f && angle <= -16.875f) {GetComponent<SpriteRenderer>().sprite = g;}
     if (angle > -16.875f && angle <= -5.625f) {GetComponent<SpriteRenderer>().sprite = h;}
     if (angle > -5.625f && angle <= 5.625f) {GetComponent<SpriteRenderer>().sprite = i;}
     if (angle >  5.625f && angle <= 16.875f) {GetComponent<SpriteRenderer>().sprite = j;}
     if (angle > 16.875f && angle <= 28.125f) {GetComponent<SpriteRenderer>().sprite = k;}
     if (angle > 28.125f && angle <= 39.375f) {GetComponent<SpriteRenderer>().sprite = l;}
     if (angle > 39.375f && angle <= 50.625f) {GetComponent<SpriteRenderer>().sprite = m;}
     if (angle > 50.625f && angle <= 61.875f) {GetComponent<SpriteRenderer>().sprite = n;}
     if (angle > 61.875f && angle <= 73.125f) {GetComponent<SpriteRenderer>().sprite = o;}
     if (angle > 73.125f && angle <= 84.375f) {GetComponent<SpriteRenderer>().sprite = p;}
     if (angle > 84.375f && angle <= 95.625f) {GetComponent<SpriteRenderer>().sprite = r;}
     if (angle > 95.625f && angle <= 106.875f) {GetComponent<SpriteRenderer>().sprite = s;}
     if (angle > 106.875f && angle <= 118.125f) {GetComponent<SpriteRenderer>().sprite = t;}
     if (angle > 118.125f && angle <= 129.375f) {GetComponent<SpriteRenderer>().sprite = u;}
     if (angle > 129.375f && angle <= 140.625f) {GetComponent<SpriteRenderer>().sprite = v;}
     if (angle > 140.625f && angle <= 151.875f) {GetComponent<SpriteRenderer>().sprite = y;}
     if (angle > 151.875f && angle <= 163.125f) {GetComponent<SpriteRenderer>().sprite = z;}
     if (angle > 163.125f && angle <= 174.375f) {GetComponent<SpriteRenderer>().sprite = za;}
     if (angle > 174.375f && angle <= 180f) {GetComponent<SpriteRenderer>().sprite = za;}
     if (angle >= -179.999f && angle <= -174.375f) {GetComponent<SpriteRenderer>().sprite = zb;}
     if (angle > -174.375f && angle <= -163.125f) {GetComponent<SpriteRenderer>().sprite = zc;}
     if (angle > -163.125f && angle <= -151.875f) {GetComponent<SpriteRenderer>().sprite = zd;}
     if (angle > -151.875f && angle <= -140.625f) {GetComponent<SpriteRenderer>().sprite = ze;}
     if (angle > -140.625f && angle <= -129.375f) {GetComponent<SpriteRenderer>().sprite = zf;}
     if (angle > -129.375f && angle <= -118.125f) {GetComponent<SpriteRenderer>().sprite = zg;}
     if (angle > -118.125f && angle <= -106.875f) {GetComponent<SpriteRenderer>().sprite = zh;}
     if (angle > -106.875f && angle <= -95.625f) {GetComponent<SpriteRenderer>().sprite = zi;}
 }


 public override void OnStartLocalPlayer(){
     Camera.main.GetComponent<CameraFollow> ().setTarget (gameObject.transform);
     }


}

Comment
Add comment · Show 1
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
avatar image iShorty11 · Apr 04, 2018 at 02:16 AM 0
Share

Have you found a solution? I have a very similar problem.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by NITRONOME · Apr 04, 2018 at 06:37 AM

yes i have. dont use high level api. if you insist on using it. you need to calculate the sprite referance(angle in my case) in a command fuction so the server knows it

Comment
Add comment · Show 1 · Share
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
avatar image iShorty11 · Apr 04, 2018 at 07:01 AM 0
Share

Gotcha, thanks! I'll play around with that concept. By itself it hasn't worked, but I think if I combine it with an RpcClient it might do the trick.

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

177 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 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

Why is my script firing 2 bullets on the client side? 0 Answers

Delay in synchronization in unity3d Unet 0 Answers

Problems syncing players in multiplayer 0 Answers

UNet - sync child transform scale 1 Answer

Trivia Game in multiplayer mode? 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