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 DLGScript · Jul 21, 2013 at 02:53 AM · networkingmultiplayersyncflashlightflare

Help| Flashlight sync' over network

I'm trying to sync the flash light , That other people will be able to see the light

This is the error: Assets/Resources/OldScripts/Misc/FlashLight.js(22,9): BCE0004: Ambiguous reference 'light': FlashLight.light, UnityEngine.Component.light.

This is a code I found: var light : Light; private var lightOn : boolean = false;

 function Update () {
     if(networkView.isMine){
         if(Input.GetKeyDown(KeyCode.F)){
             if(!lightOn){
                 networkView.RPC("TurnLightOn", RPCMode.All, true); //Turn on
             }
             else{
                 networkView.RPC("TurnLightOn", RPCMode.All, true); //Turn off
             }
             lightOn = !lightOn;
         }
     }
 }
 
 @RPC
 function TurnLightOn (on : boolean) {
     lightOn = on;
     if(on){
         light.intensity = 1;
     }
     else{
         light.intensity = 0;
     }
 }

ALSO I WANT TO KNOW: HOW TO SYNC THE FLARE OF THE LIGHT? I MEAN, HOW TO MAKE PEOPLE TO GET Blinded FROM THE FLARE OF MY FLASHLIGHT WHEN THERE'RE LOOKING AT ME. THANKS !

Comment
Add comment · Show 5
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 Dave-Carlile · Jul 21, 2013 at 02:54 AM 0
Share

So what is the question regarding syncing the flashlight? You have code to do it already.

avatar image DLGScript · Jul 21, 2013 at 07:56 AM 0
Share

I forgot to post the error: Assets/Resources/OldScripts/$$anonymous$$isc/FlashLight.js(22,9): BCE0004: Ambiguous reference 'light': FlashLight.light, UnityEngine.Component.light.

avatar image Benproductions1 · Jul 21, 2013 at 11:15 PM 0
Share

You created a variable light. But light already refers to the light component added to the object. Thats why you get that error. Rename your variable!

avatar image DLGScript · Jul 22, 2013 at 08:31 AM -1
Share

This is the new script:

 var lightt : Light;
 private var lightOn : boolean = false;
 
 function Update () {
     if(networkView.is$$anonymous$$ine){
         if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.F)){
             if(!lightOn){
                 networkView.RPC("TurnLightOn", RPC$$anonymous$$ode.All, true); //Turn on
             }
             else{
                 networkView.RPC("TurnLightOn", RPC$$anonymous$$ode.All, false); //Turn off
             }
             lightOn = !lightOn;
         }
     }
 }
 
 @RPC
 function TurnLightOn (on : boolean) {
     lightOn = on;
     if(on){
         lightt.light.intensity = 1;
     }
     else{
         lightt.light.intensity = 0;
     }
 }

No errors :) But now even I can't see the light, cause he's not turnning on\off :\ It's not working

avatar image Benproductions1 DLGScript · Jul 22, 2013 at 08:42 AM 0
Share

It doesn't work because you are also caling the RPC on yourself.

light is on
When the key is pressed, an RPC is sent to ALL.
The RPC is "recieved" and sets light off
light is toggled back on
light is on

As you can se, simply following the flow of your program solves the problem :)
This process is called "desk Checking". You simply run through your program as if you were the computer.

As a last thing. DO NOT post questions in answers. If it doesn't fix your problem but it is part of the question, edit the question or post a comment. Answers should always answer the question

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jeuxbastien3311 · Jul 23, 2013 at 01:31 PM

 public var thisLight : Light;
 
 function Start()
 {
    thisLight = GetComponent("Light");
 }
 
 function Update()
 {
    if(Input.GetKeyDown("f") && networkView.isMine)
    {
       if(thisLight.enabled)
       {
          networkView.RPC("DisableLight", RPCMode.AllBuffered);
       }
       else
       {
          networkView.RPC("EnableLight", RPCMode.AllBuffered);
       }
    }
 }
 
 @RPC
 function EnableLight()
 {
    thisLight.enabled = true;
 }
 
 @RPC
 function DisableLight()
 {
    thisLight.enabled = false;
 }
Comment
Add comment · Show 4 · 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 Benproductions1 · Jul 23, 2013 at 11:41 PM 0
Share

$$anonymous$$ind adding some explanation to your answer? :)

PS: You will have problems using this exact method, due to RPC Buffering

avatar image jeuxbastien3311 · Jul 24, 2013 at 01:38 AM 0
Share

I have a problem with a script I want to do the same thing but with this script

can you help me please :)

     //Name this script Flashlight and attach it to your player for instance
      
     var lightSource : Light; //Connect the light source in the Inspector
     static var energy : float = 100; //The energy amount of the flashlight
     static var turnedOn : boolean = false; //Boolean to check whether it's turned on or off
     private var drainSpeed : float = 2.0; //The speed that the energy is drained
      
     function Update () {
     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.F)) ToggleFlashlight();
     }
      
     //When the player press F we toggle the flashlight on and off
     function ToggleFlashlight () {
     turnedOn=!turnedOn;
     if (turnedOn && energy>0) {
     TurnOnAndDrainEnergy();
     } else {
     lightSource.enabled = false;
     }
     }
      
     //When the flashlight is turned on we enter a while loop which drains the energy
     function TurnOnAndDrainEnergy () {
     lightSource.enabled = true;
     while (turnedOn && energy>0) {
     energy -= drainSpeed*Time.deltaTime;
     yield;
     }
     lightSource.enabled = false;
     }
      
     //This is called from outside the script to alter the amount of energy
     static function AlterEnergy (amount : int) {
     energy = $$anonymous$$athf.Clamp(energy+amount, 0, 100);
     }
avatar image jeuxbastien3311 · Jul 24, 2013 at 01:39 AM 0
Share

How to Flashlight sync' over network ?

avatar image Benproductions1 · Jul 24, 2013 at 02:00 AM 0
Share

@jeuxbastein3311 How about you ask a question, ins$$anonymous$$d of posting a comment? No one will answer you here

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

18 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

Related Questions

Unity networking tutorial? 6 Answers

How would I continue an object's movement in the same direction as per last user input? 1 Answer

How to sync the position and rotation of a player controlled object over network? 0 Answers

Sending Animation Over Network 0 Answers

Help| Sync' boolean variable (Friendly Fire) 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