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 /
avatar image
0
Question by MoodyCake · Jul 27, 2016 at 10:55 AM · c#multiplayerinvisible

Cloaking script for Multiplayer C#

Hi, I have a question about my script,

I was wondering if I needed to use an [RPC] to show the other players and the server that my player is cloaking, but every time I cloak it uses the energy and other players can't see me cloak, I know that the "Graphics" disappear because the shadow disappears on the client's computer but for other players nothing happens.

Here is the script :

 using UnityEngine;
 using System.Collections;
 /// <summary>
 /// This script is attached to the player.
 /// 
 /// This script accesses the BlinkEnergy script.
 /// </summary>
 public class Cloaking : MonoBehaviour {
 
     // <Variables>
 
     // Particle effect.
     public GameObject cloakEffect;
 
 
     // Time cloak lasts for
     private float activeTime = 6;
 
 
     // Quick reference
     private Transform playerGraphics;
 
     private Transform myTransform;
 
 
     // Used to affect the energy.
     private BlinkEnergy energyScript;
 
     private float cloakCost = 80;
 
 
     // Determine where the cloakEffect should be instantiated.
     private Vector3 startPosition = new Vector3();
 
     // <Variables END>
 
     // Use this for initialization
     void Start () {
         if (GetComponent<NetworkView> ().isMine == true) {
             myTransform = transform;
 
 
             playerGraphics = myTransform.FindChild ("Graphics");
 
 
             // Access the BlinkEnergy script.
             energyScript = myTransform.GetComponent<BlinkEnergy> ();
         }
 
         else 
         {
             enabled = false;
         }
     }
     
     // Update is called once per frame
     void Update () {
         if (Input.GetButtonDown ("Cloak") && Cursor.visible == false && energyScript.blink >= cloakCost)
         {
             energyScript.blink = energyScript.blink - cloakCost;
 
             startPosition = myTransform.position;
 
             DisableAndStartTimer();
         }
     }
 
 
 
     void DisableAndStartTimer()
     {
         //Disable the player's graphics so that they dissappear for a moment.
         
         playerGraphics.GetComponent<Renderer>().enabled = false;
         
         
         //Run a Coroutine that will limit the time that the player can go invisible for.
         
         StartCoroutine(RunForAMoment());
         
     }
 
 
     IEnumerator RunForAMoment ()
     {
         yield return new WaitForSeconds(activeTime);
 
         //Enable the graphics so that the player can be seen again.
         
         playerGraphics.GetComponent<Renderer>().enabled = true;
         
         
         //Send out an RPC across the network so that everyone sees the cloak effect.
         
         GetComponent<NetworkView>().RPC("CloakEffect", RPCMode.OthersBuffered, startPosition);
     }
 
 
     [RPC]
     void CloakEffect (Vector3 startPos)
     {
         Instantiate(cloakEffect, startPos, Quaternion.identity);
     }
 }
Comment
Add comment · Show 2
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 CodeElemental · Jul 28, 2016 at 07:28 AM 0
Share

Did my answer solve your problem?

avatar image MoodyCake CodeElemental · Jul 28, 2016 at 01:11 PM 0
Share

No, unfortunately it's still client sided. I haven't had time to test it out much, but I'll let you know when it works.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by CodeElemental · Jul 27, 2016 at 11:00 AM

When calling RPC's the code that executes on everyone's computer is inside the method that is called. In your method, the only thing thats inside the RPC code is the instantiating of the effect prefab. You should add the disabling of renderers inside it too.

 [RPC]
 void CloakEffect (Vector3 startPos)
 {
      Instantiate(cloakEffect, startPos, Quaternion.identity);
      playerGraphics.GetComponent<Renderer>().enabled = false;
 }
Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Renderer on object disabled after level reload 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to make a simple co-op (2-player) Game? 1 Answer

How to make enemy players invisible using Photon? 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