Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Ted 1 · May 03, 2011 at 06:45 PM · multiplayervariableserverclientsending

Multiplayer - sending a variable from server to client

Hello,i am pretty new in scripting and i got this problem : The problems appear when i am a client.If i am the server everything is ok.So,as you can see i am trying to send a value from a variable that only the server owns to the client.Only 1 way.Let's say that I want to send the client the current server time.Why if i print DispTemp inside SetVariable function i get the right number(25) and if i print it outside it i get something like : 100 and then 25 and then 100 and then 25 and so on...So this way when i use if(networkView.isMine && Network.isClient){ GUI.Box(new Rect(0,0,Screen.width / 16,Screen.height / 32),DispTemp + "C");} i'll always get 100 instead of 25 :S. As far as i noticed,DispTemp = 25 only when !networkView.isMine :S How can i make it to be equal with the value boadcasted by the server all of the time? Please help me and thanks in advance.An anwser in JavaScript would be welcome aswell :D

using UnityEngine; using System.Collections;

public class MonoTestVar : MonoBehaviour { int Temp = 25; int DispTemp = 100;

void Update(){ Debug.Log(DispTemp);

if(Network.isServer && networkView.isMine){ networkView.RPC("SetVariable", RPCMode.All, Temp);} }

[RPC] void SetVariable(int newTemp){ //This RPC is in this case always called by the server, // but executed on all the clients DispTemp = newTemp;

} void OnGUI(){ if(networkView.isMine && Network.isClient){ GUI.Box(new Rect(0,0,Screen.width / 16,Screen.height / 32),DispTemp + "C");} if(networkView.isMine && Network.isServer){ GUI.Box(new Rect(0,0,Screen.width / 16,Screen.height / 32),DispTemp + "C");} } }

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AKAssassin · May 03, 2011 at 07:14 PM

If you want the server to change the value all of the time then take out the check networkView.isMine.

You wouldn't want to check that because even though the code is running on the server he still may not actually own the networkview, so you would just check.

if(Network.isServer){
    networkView.RPC("SetVariable", RPCMode.All, Temp);}
}

That way the server will always update the value even if it doesn't own the networkView on the object.

Comment
Add comment · Show 2 · 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 Ted 1 · May 03, 2011 at 08:54 PM 0
Share

Yeah,i tried that before but if i want Temp to increase like if(Network.isServer){ Temp += 1; networkView.RPC("SetPosition", RPC$$anonymous$$ode.All, Temp);} }

It will give me again 2 values : 1 is the one calculated by the server and the other one is calculeted by the client :S Please help me fix this :(

avatar image Ted 1 · May 04, 2011 at 04:28 PM 0
Share

Baisicaly if i put a debug.log inside the SetVariable function DispTemp = Temp(the one calculated by the server) BuT if i place it in the update function for instance i'll get it's default value...Why is that happening?

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

No one has followed this question yet.

Related Questions

Unity networking tutorial? 6 Answers

Missing line renderer in multiplayer? 0 Answers

Would it be possible for every person to host the server.... And yet no one. 1 Answer

problem in unity multiplayer about "ccu" It is limited to 200 ccu 1 Answer

Passing a variable to other Players 1 Answer


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