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 cyunide · Sep 27, 2017 at 10:38 PM · networkingmultiplayer

ClientRPC running on host, not client. Please help! (Code Included)

Ok so I am working on a game that will have a StorageBox that will have random loot in it. The box works just fine, meaning loot is spawned, populated, etc. Where I got stuck for days is I'm trying to set a variable isBusy on the box so that if a player has it open, other players cannot open it. I'm afraid I may be going about this all wrong, surely it cannot be this hard!

StorageBox is a prefab that has StorageInventory.cs script on it. Player has PlayerMove.cs on it.

Here is the code used: PlayerMove:

     void Update () {    
         if (!isLocalPlayer)
             return;        
         var x = Input.GetAxis("Horizontal")*0.1f;
         var z = Input.GetAxis("Vertical")*0.1f;        
         transform.Translate(x, 0, z);
         RaycastHit hit;
         float theDistance;
 
         Vector3 forward = transform.TransformDirection (Vector3.forward) * 10;
         // E Key Handler
         if (Input.GetKeyDown (inputManagerDatabase.StorageKeyCode)) {
             if (Physics.Raycast (transform.position, (forward), out hit)) {
                 theDistance = hit.distance;
 
                 if (theDistance <= 1.6f && hit.collider.gameObject.tag == "StorageBoxGeneric") {
                     CmdStorageBoxGenericBusy(hit.collider.gameObject);
                 }
             }
         }
         // End E Key Handler
     }
 
 
     [Command]
     void CmdStorageBoxGenericBusy(GameObject g) {
         STI = g.GetComponent<StorageInventory> ();
         if (STI.isBusy == true) {
             STI.CmdSetBusy (false);
             STI.RpcOpenInventoryWithTimer();
         } else {
             STI.CmdSetBusy (true);
             STI.RpcOpenInventoryWithTimer();
         }
     }

StorageInventory:

 public void CmdSetBusy(bool b) {
         isBusy = b;
         showStorage = b;
     }
     [ClientRpc]
     public void RpcOpenInventoryWithTimer() {
         if (showStorage == true && isBusy == true) {
             Debug.Log ("Opening");
             //startTimer = Time.time;
             //showTimer = true;
             //yield return new WaitForSeconds (timeToOpenStorage);
             inv.ItemsInInventory.Clear ();
             inventory.SetActive (true);
             addItemsToInventory ();
             //showTimer = false;
             //if (timer != null)
                 //timer.SetActive (false);
         } else {
             Debug.Log ("Closing");
             storageItems.Clear ();
             setListofStorage ();
             inventory.SetActive (false);
             inv.deleteAllItems ();
             tooltip.deactivateTooltip ();
         }
     }


The problem is when player2 (A client) opens the box, it opens on player1 (The host) screen only. The host can open it fine, but the player cannot.

So I guess the question I have specifically is this: When any player (From the PlayerMove.cs script) sends a [Command] to run code on the server, how can I have that code [ClientRPC] run ONLY on the player that called it? Again I may be going about this all wrong, but I need help please! Thank you!

Comment
Add comment · Show 1
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 cyunide · Sep 27, 2017 at 10:40 PM 0
Share

Also even though CmdSetBusy is named that way, it is NOT a [Command]. It was when i was trying something else, but is not now. I just never removed the Cmd in the routine name.

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

176 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

Related Questions

Multiplayer First Person shooter similar to Battlefield 1 Answer

Photon & Unity Question 0 Answers

How to smoothly interpolate game object positions in a network game? 0 Answers

Multiplayer Game Networking Layer Problem 0 Answers

Unet: How can I know the percentage of packets lost? 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