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 Purple_Ice · Mar 31, 2016 at 03:11 PM · networkingspritesynchronization

Syncing sprites over network using UNET on Unity 5.3

This is my current code for instantiating floor in game (2D top down game with dungeon like levels)

 public void PlaceFloor(Vector2 pos)
     {
         var onFloor = Physics2D.Linecast(pos, pos, floorLayerMask);
         if(!onFloor)
         {
             GameObject floor = GameObject.Instantiate (floorPrefab, pos, Quaternion.identity) as GameObject;
             floor.layer = floorLayer;
             floor.transform.position = pos;
             floor.transform.parent = transform.FindChild("Floor");
             floor.GetComponent<SpriteRenderer>().sprite = floorSprites[0];
             FloorArray.Add(floor);
             NetworkServer.Spawn(floor);
         }
     }

I run an autotile script right after all tiles are placed, but it seems that this doesn't really do anything on client end:

 public void AutotileFloor()
     {
         foreach(GameObject floor in FloorArray)
         {
             Vector2 Up = new Vector2(floor.transform.position.x, floor.transform.position.y + 1);
             Vector2 Right = new Vector2(floor.transform.position.x + 1, floor.transform.position.y);
             Vector2 Down = new Vector2(floor.transform.position.x, floor.transform.position.y - 1);
             Vector2 Left = new Vector2(floor.transform.position.x - 1, floor.transform.position.y);
             
             var U = Physics2D.Linecast(Up, Up, floorLayerMask);
             var R = Physics2D.Linecast(Right, Right, floorLayerMask);
             var D = Physics2D.Linecast(Down, Down, floorLayerMask);
             var L = Physics2D.Linecast(Left, Left, floorLayerMask);
             
             var tileID = 0;
             if(U)
             {
                 tileID += 1;
             }
             if(R)
             {
                 tileID += 2;
             }
             if(D)
             {
                 tileID += 4;
             }
             if(L)
             {
                 tileID += 8;
             }
             floor.GetComponent<SpriteRenderer>().sprite = floorSprites[tileID];
         }
     }
 


floorSprites are loaded from resources where I put all my tilesets... so since this won't work on it's own, are there any functions specifically for sprites or something like that? Currently if I connect with unity editor I can select all invisible floors placed and level looks exactly the same like on host, so it's working, but I don't know how to sync sprites properly, does anyone know if anyone had similar problem and it was already solved somewhere else (if it was then sorry for not googling long enough :( ) or could just help me with this? I am not asking for code, I am just lost on what I should do to sync all tiles (every type of wall/floor has 16 variations, every type is in individual image if that matters, all placed in resources folder then I load it onAwake with floorSprites = Resources.LoadAll(floorTileset);)

Basically my question is how, if possible and it doesn't use too much bandwitdh, I could sync spriterenderer or even the whole object to make it simpler? (not saying simpler is always better) If there are several ways, I'd like to know the best one, not the easiest one, thank you for your help in advance.

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

85 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

Related Questions

How to Update Objects Sprite to the Network 1 Answer

How do I sync Network-Server objects to clients? / Is my solution okay? 0 Answers

How do i get the two client's units to match up rather than be incorrect units? 1 Answer

[uNET] Instantiated gameobjects not syncing for new clients 1 Answer

Setting function to run on all clients but only work on the player that called it 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