Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Barrufy96 · Aug 17, 2018 at 10:13 PM · networkingrpcsetactiveclick objects

RPC activating gameobject on Host instead of on the Client

Hi guys. I am trying to make a player put on a helmet when clicking on it. There is a helmet on the ground tagged as "Helmet", and the another helmet on the player prefab with the renderers deactivated so it is invisible, tagged as "Object".

What I try to do with my code is to click on the helmet on the floor, make it unactive, and then set the renderers on for the helmet on the head of the player that has clicked.

What is happening to me is that when my Host clicks the helmet on the floor everything works perfect, but when it's the Client who clicks, the helmet that turns active it is still the one on the Host head.

PD: This script is turned on on for the local player through another script that enables it using the function "OnStartLocalPlayer"

Here's my script :D

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Networking;
 
 public class Helmet : NetworkBehaviour {
 
     public Transform cameraTransform;
 
     GameObject helmetFloor;
     GameObject helmetHead;
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
                
 
         RaycastHit hit;
         Vector3 rayPos = cameraTransform.position + cameraTransform.forward * 1f;
         Debug.DrawRay(rayPos, cameraTransform.forward * 5f, Color.green, 0.5f);
 
         if (Physics.Raycast(rayPos, cameraTransform.forward, out hit, 5f))
         {
             if (hit.transform.tag == "Helmet")
             {              
 
                 if (Input.GetMouseButtonDown(0))
                 {                    
                     CmdHelmet();
                 }
             }
         }
 
     }
 
     [Command]
     void CmdHelmet()
     {
               
         RpcHelmet();
     }
 
     [ClientRpc]
     void RpcHelmet()
     {
         helmetFloor = GameObject.FindGameObjectWithTag("Helmet");
         helmetHead = GameObject.FindGameObjectWithTag("Object");
         helmetFloor.SetActive(false);
         helmetHead.GetComponent<Renderer>().enabled = true;
     }
 }

This is for my thesis at university (yeah, it got weird), so all the help would be much appreciated. Thanks!

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 Barrufy96 · Aug 17, 2018 at 05:20 PM 0
Share

Guys I solved it! I don't know why I thought about this because I think it was a long shot but it worked!

I declared a public GameObject helmetHead, and I put it in the inspector ins$$anonymous$$d of using the find with tag function. I guess that since once you are a player you cannot access the other players helmets, the script has no other option than to enable yours. :D

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

130 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

Related Questions

Experience going to both players, Photon Unity Networking 0 Answers

How to send timestamp via RPC so it was relative to the receiver? 1 Answer

NetworkMessageInfo sender.guid set to empty string "" or "0"? 1 Answer

Photon (PUN) Type Serialization Error on RPC 2 Answers

Unet RPC call not working on clients 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