• 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 /
This question was closed May 07, 2014 at 01:35 AM by thornekey for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by thornekey · Apr 28, 2014 at 07:13 AM · c#networkingmultiplayer

Name Plate works but is updating every frame.

I made a name plate script for my multiplayer game. Which works, but its updating every frame to the other players name because I have put it in an update function. My problem is figuring out which function to use.

     public string getPlayerName;
     public TextMesh NAMEPLATE;
 
     void Update () {
         NAMEPLATE = gameObject.GetComponent<TextMesh>();
         networkView.RPC("getName", RPCMode.All, PlayerPrefs.GetString("Player_Name"));
     }    
 
     [RPC]
     void getName(string name) {
         NAMEPLATE.text = name;
     }

As you can see, its being called every single frame. What else can I use for a function? I cant use on player connected because it wont get the first player (the server)...

thanks 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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by FLASHDENMARK · Apr 28, 2014 at 08:15 AM

Use buffered RPCs. They are made for this very purpose.

     public string getPlayerName;
     public TextMesh NAMEPLATE;
 
     void Awake (){
         NAMEPLATE = gameObject.GetComponent<TextMesh>();
         networkView.RPC("GetName", RPCMode.AllBuffered, PlayerPrefs.GetString("Player_Name"));
     }
 
  
     [RPC]
     void GetName(string name) {
        NAMEPLATE.text = name;
     }

Everyone who joins will receive this RPC because it is buffered.

Comment
Add comment · Show 5 · 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 thornekey · Apr 28, 2014 at 08:17 AM 0
Share

ah i see. I will try!

EDIT: Thanks! that worked great :D

So buffered is only called when a player joins?

Also, do you think you could help me make it aim towards the camera the whole time?

Ive tried,
transform.LookAt(Camera.main.transform);

but it didnt work

avatar image FLASHDENMARK · Apr 28, 2014 at 08:20 AM 0
Share

If you haven't seen already then this might suffice for a start:

RPC linky

avatar image FLASHDENMARK · Apr 28, 2014 at 08:33 AM 0
Share

Buffered RPCs are called immediately and when a player joins.

The LookAt function should work, but properly not how you want, I could imagine. What exactly doesn't work with LookAt()? It works for me.

avatar image thornekey · Apr 28, 2014 at 10:06 AM 0
Share

its looking at the local players camera. not the other players.

avatar image FLASHDENMARK · Apr 28, 2014 at 03:40 PM 0
Share

Remember that there can only be one $$anonymous$$ain Camera when using Camera.main. If there are more main cameras it will pick the one it finds first.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Unity networking tutorial? 6 Answers

Multiplayer desynchronize when grabbing an object by code. 0 Answers

[PhotonUnityNetwork] Synchronize colors among players. 1 Answer

Only one player for the host but two for the client, 0 Answers

How to synchronize disable and enabling game objects over the network? 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