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 Fewpwew130 · Oct 07, 2014 at 08:42 PM · variableserverclient

Sending a variable from the server to a client

Hello dear community. I am trying to implement a simple idea: if a player connects to a server, he/she gets notified how long the server has been up.

I produced some code and tried to test it, but it doesn't work: players see wrong uptime (done in colour rendering). In my code a player, connected to server sees his colour change (if uptime gets more than a certain value), but new players, who have connected afterwards see the uptime start from the beginning and don't percieve the colour of other players. Network view component has been attached to both player prefab and server object.

I am supplying 2 scripts below and asking for help. Could you please tell me how to properly send the uptime variable to a newly connected player, so he/she can use it? Thank you!

////////// SERVER.CS //////////

 using UnityEngine;
 using System.Collections;
 
 public class server : MonoBehaviour {
 
     public int i;
        public void Start()
     {
     }
 
     void OnServerInitialized(){
         StartCoroutine (Uptimecounter ());
     }
 
     void OnPlayerConnected(NetworkPlayer player) {
         Debug.Log("Player connected");
         
     }
 
        [RPC]    
     IEnumerator Uptimecounter(){
         for (i = 0; i < 100; i++){
             yield return new WaitForSeconds(1);
 //            Debug.Log (i);
             
         }
     }
 }





////////////// ONCONNECT.CS //////////////

 using UnityEngine;
 using System.Collections;
 
 public class onconnect : MonoBehaviour {
 
     public server link;
 
     void Start () {
     
         link = GameObject.Find("NetworkManager").GetComponent<server>();
         
         Debug.Log (link.i);
     }
     
 
     void Update () {
 
         if (link.i < 5) {
             renderer.material.color = Color.red;
         }
         if ((link.i > 5)&&(link.i<10)) {
             renderer.material.color = Color.blue;
         }
         if ((link.i > 10)&&(link.i<15)) {
             renderer.material.color = Color.green;
         }
     }
 }
 


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

28 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

Related Questions

On/off switch from server to clients live 1 Answer

Multiplayer - sending a variable from server to client 1 Answer

RPC calls, how to transfer data from server to client and back? 0 Answers

Networking Question 1 Answer

Network , new player can't see the old 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