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 /
avatar image
0
Question by berssi98 · Apr 20, 2020 at 08:51 AM · multiplayerupdateimageclientupdate function

How do I update an image to all connected Players on a Multiplayer server?

Hello, I am currently working on a Multiplayer Game. As a part of this game, players can draw on an image I chose. For this i used this code:

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

public class paint : MonoBehaviour { int i; int i2; Color c; float f;

 int sw;
 int sh;

 float mx;
 float my;

 int px;
 int py;

 //drop a texture into the inpector 
 //in the texture import settings you must set the type to "advanced"
 //and then set "read/write" to true!!!!!!!

 public Texture2D original;

 Texture2D myimage;

 public int brush;
 public int erase;
 int oldp;

 public Color drawcolor;
 private NetworkIdentity myimageID;



 void Start()
 {

     if (original == null) { original = new Texture2D(400, 300); }

     // change these next three variables to whatever you want!!!
     drawcolor = Color.white;
     brush = 1;
     erase = 20;

     //copy our original into our new paintable image 
     myimage = new Texture2D(original.width, original.height);

     i = original.width;
     while (i > 0)
     {
         i--;
         i2 = original.height;
         while (i2 > 0)
         {
             i2--;
             c = original.GetPixel(i, i2);
             myimage.SetPixel(i, i2, c);
         }
     }

     myimage.Apply();
     myimage.filterMode = FilterMode.Point;//<remove this if you want it more fuzzy

 }

 void OnGUI()
 {
     GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), myimage);
 }

 void Update()
 {


     sw = Screen.width;
     sh = Screen.height;

     mx = Input.mousePosition.x / sw;
     my = Input.mousePosition.y / sh;

     px = Mathf.RoundToInt(myimage.width * mx);
     py = Mathf.RoundToInt(myimage.height * my) - 1;


     if (px + py != oldp)
     {// <-- only draw when mouse moves for proficiency
         oldp = px + py;

         if (Input.GetMouseButton(0))
         {//------mouse right button  draws--------

             px += -Mathf.RoundToInt(brush * .5f);
             py += -Mathf.RoundToInt(brush * .5f);

             i = 0;
             while (i < brush)
             {
                 i++;//<--next two loops for brush size
                 i2 = 0;
                 while (i2 < brush)
                 {
                     i2++;
                     if (px + i > -1 && px + i < myimage.width)
                     {//<---dont try to draw off image width
                         if (py + i2 > -1 && py + i2 < myimage.height)
                         {//<---dont try to draw off image height

                             myimage.SetPixel(px + i, py + i2, drawcolor);


                         }
                     }
                 }
             }
             myimage.Apply();

         }


         if (Input.GetMouseButton(1))
         {//-----mouse left erases----

             px += -Mathf.RoundToInt(erase * .5f);
             py += -Mathf.RoundToInt(erase * .5f);

             i = 0;
             while (i < erase)
             {
                 i++;
                 i2 = 0;
                 while (i2 < erase)
                 {
                     i2++;
                     if (px + i > -1 && px + i < myimage.width)
                     {
                         if (py + i2 > -1 && py + i2 < myimage.height)
                         {

                             c = original.GetPixel(px + i, py + i2);//<--grab pixel from original for erasing
                             myimage.SetPixel(px + i, py + i2, c);


                         }
                     }
                 }
             }
             myimage.Apply();
         }
     }
 }  

}

This is all working fine, but only for every single Player, so the other Players can't see what one has drawn... As this is my first ever game i dont really know, how to fix this issue and update the drawings to all others players... I hope you understand my problem and can help me to solve it!

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

216 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Multiplayer - Parent's children not syncing 0 Answers

Multiplayer Spawning the Client on the fixed locations, i.e. override Round robin as well as Random 0 Answers

update position of cube 0 Answers

Smartfox Multiplayer Update problem 0 Answers

Online Multiplayer (Dedicated Hosting) 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