- Home /
 
               Question by 
               D3m0nE · Mar 12, 2013 at 06:04 AM · 
                gameobjectnetworkrpc  
              
 
              Active/Dis-active Gameobject By RPC
Hello Everyone I'm Trying to Active/Dis-active Object and send it by RPC but its notworking
     public GameObject Light1;
     public GameObject Light2;
 
 If(ITurnItOn == True){
 
             Light1.SetActive(true);
             Light2.SetActive(true);
 networkView.RPC("TheLights",RPCMode.OthersBuffered,Light1,Light2,"true");
 
 }
 else{
 
             Light1.SetActive(false);
             Light2.SetActive(false);
 
 networkView.RPC("TheLights",RPCMode.OthersBuffered,Light1,Light2,"false");
                 
 }
 
 
 
     [RPC]
     public void TheLights(GameObject light1,GameObject light2,string Switch){
     if(Switch == "true"){
     light1.SetActive(true);
     light2.SetActive(true);    
     }
     else if(Switch == "false"){
     light1.SetActive(false);
     light2.SetActive(false);        
         }
 
     }
 
               Comment
              
 
               
               
               Best Answer 
               Wiki 
              
 
              Answer by KiraSensei · Mar 12, 2013 at 07:00 AM
Have a look at this page
You cannot pass a game object as an argument (light1 and light2). Make sure that every player has its variables Light1 and Light2 (the public ones at the beginning of your script) valuated, and your method should be like :
 [RPC]
 public void TheLights(string Switch){
     if(Switch == "true"){
         Light1.SetActive(true);
         Light2.SetActive(true);    
     }
     else if(Switch == "false"){
         Light1.SetActive(false);
         Light2.SetActive(false);     
     }
 }
Note that I called the variables Light1 and Light2 in the method, and not light1 and light2.
Good luck with your game !
if you want to write a little less and save internet, you could do:
 [RPC]
  public void TheLights(bool Switch){
          Light1.SetActive(Switch);
          Light2.SetActive(Switch);     
  }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                