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 recon472 · Jan 26, 2014 at 01:59 AM · c#multiplayerphotonitween

RPC called by OnPhotonPlayerConnected doesn't work

this is my sript I use for opening doors. when new player connects, I need to tell him whether the doors are closed or open. I wanted to send rpc to close the door when anyone connects if the doors are closed, but nothing happens

 using UnityEngine;
 using System.Collections;
 
 public class door_interact : Photon.MonoBehaviour {
     
     public int speed = 4;
     public string axis = "z";
     public float coord1 = -10.12562f;
     public float coord2 = -15.18888f;
     public float coord3 = -4.210109f;
     public float coord4 = 0.9528589f;
 
     public void OnLookEnter()
     {
         if(Input.GetKeyUp("e"))
         {
             if (gameObject.transform.root.GetComponent<ship_stats>().door_locked == false)
             {
                 gameObject.GetComponent<PhotonView>().RPC("open_close",PhotonTargets.All);
             }
         }
     }
 
     public void OnPhotonPlayerConnected ()
     {
         gameObject.GetComponent<PhotonView>().RPC("open_close_update",PhotonTargets.All);
     }
 
     [RPC]
     public void open_close()
     {
             if(gameObject.transform.root.gameObject.GetComponent<ship_stats>().door_bridge_open == true)
             {
                 iTween.MoveTo(gameObject.transform.parent.gameObject.transform.parent.gameObject.transform.FindChild("door_left").gameObject,iTween.Hash("islocal",true,axis,coord1,"time",speed));
                 iTween.MoveTo(gameObject.transform.parent.gameObject.transform.parent.gameObject.transform.FindChild("door_right").gameObject,iTween.Hash("islocal",true,axis,coord3,"time",speed));
                 gameObject.transform.root.gameObject.GetComponent<ship_stats>().door_bridge_open = false;
             }
             else
             {
                 iTween.MoveTo(gameObject.transform.parent.gameObject.transform.parent.gameObject.transform.FindChild("door_left").gameObject,iTween.Hash("islocal",true,axis,coord2,"time",speed));
                 iTween.MoveTo(gameObject.transform.parent.gameObject.transform.parent.gameObject.transform.FindChild("door_right").gameObject,iTween.Hash("islocal",true,axis,coord4,"time",speed));
                 gameObject.transform.root.gameObject.GetComponent<ship_stats>().door_bridge_open = true;
             }
     }
 
     [RPC]
     public void open_close_update()
     {
         if(gameObject.transform.root.gameObject.GetComponent<ship_stats>().door_bridge_open == false)
         {
             iTween.MoveTo(gameObject.transform.parent.gameObject.transform.parent.gameObject.transform.FindChild("door_left").gameObject,iTween.Hash("islocal",true,axis,coord1,"time",speed));
             iTween.MoveTo(gameObject.transform.parent.gameObject.transform.parent.gameObject.transform.FindChild("door_right").gameObject,iTween.Hash("islocal",true,axis,coord3,"time",speed));
             gameObject.transform.root.gameObject.GetComponent<ship_stats>().door_bridge_open = false;
 
         }
     }
 }
 
Comment
Add comment · Show 4
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 recon472 · Jan 27, 2014 at 12:27 AM 0
Share

anyone? please I cant find out whats wrong. or any alternative way?

avatar image recon472 · Jan 27, 2014 at 11:28 PM 0
Share

c'mon people.

avatar image tayloredgames · Jan 28, 2014 at 02:39 AM 0
Share

Hey mate - have you tried a bit debugging to see if the open_close() method is being called? Chuck a Debug.Log("RPC called") into open_close before the if statements. Additionally check if you have attached a PhotonView component to the GameObject you're referring to.

avatar image recon472 · Jan 28, 2014 at 09:36 AM 0
Share

when both players are connected synchronization via open_close works wonderfully. when new player connects the open_close_update function does actually happen (confirmed via Debug.Log), but it doesn't change anything on the new player script. maybe the player scripts has not been loaded yet by the time the function is called? new player is instantiated as soon as the game connects to room

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Jellezilla · Jan 28, 2014 at 09:58 AM

When the second player joins, I'm assuming that: door_bridge_open == true for that very client, seeing since the only way you set it to false is with the first player by pressing e, right?

However, the second player has not received this information, if it has been set to false, while the second player still hasn't joined the game.

Whenever a new player connects it checks if it is false, which it cannot be unless it is stated so at the start of the application or he receives data about what has happened in the game before he joined.

Hope this is somewhat a help to you. If not, you should try and post it on the Exit-Games forum (Photon's own). They are usually very helpful.

Good luck.

Comment
Add comment · Show 5 · 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 recon472 · Jan 28, 2014 at 10:28 AM 0
Share

yeah well that's what I am ai$$anonymous$$g for. the open_close function happens when player pressess e, but the open_close_update function should happen everytime someone connects. and it actually does, it just doesn't do anything on the new player part which I frankly don't understand since it's the same code in both cases... thanks for the tip

avatar image Jellezilla · Jan 28, 2014 at 05:54 PM 0
Share

But the open_close method only checks if the "door_bridge_open" is false. Which it isn't when a player connects.

So are you trying to make sure that all changes made in the scene will be visible to the newly connected player or that the method above will open/close doors whenever a new player connects?

The latter is really easy to implement, however the one about visible changes for new players is something I was too afraid to touch upon when playing around with the Photon plugin myself.

avatar image recon472 · Jan 28, 2014 at 10:15 PM 0
Share

well door_bridge_open is boolean so for the other option there is else in the if statement. it is the first one, I am trying to update all changes. well I just need to close the doors for the new player. aaah I see the error now. in the function open_close_update it actually checks it on their side I see. I'll try to rewrite it as I know what's wrong now and get back here with a result

avatar image recon472 · Jan 28, 2014 at 11:06 PM 0
Share

so here is the final (working) result (the doors are closed by default)

when new player connects, I'll check which doors are different from default (open) and make an RPC call to close em.

Thanks, you helped me a lot.

     void OnPhotonPlayerConnected()
     {
         if(gameObject.transform.root.gameObject.GetComponent<ship_stats>().airlock_in_open == true)
         gameObject.GetComponent<PhotonView>().RPC("open_airlock_in",PhotonTargets.All);
     }
 
     [RPC]
     public void open_airlock_in()
     {
         iTween.$$anonymous$$oveTo(gameObject.transform.FindChild("airlock_in").gameObject.transform.FindChild("door_left").gameObject,iTween.Hash("islocal",true,"z",door_airlock_in_left_open,"time",speed_small));
         iTween.$$anonymous$$oveTo(gameObject.transform.FindChild("airlock_in").gameObject.transform.FindChild("door_right").gameObject,iTween.Hash("islocal",true,"z",door_airlock_in_right_open,"time",speed_small));
         gameObject.transform.root.gameObject.GetComponent<ship_stats>().airlock_in_open = true;
     }
avatar image Jellezilla · Jan 29, 2014 at 11:54 PM 0
Share

Glad I could help :)

Remember to mark answer as correct if it suits. Take care.

avatar image
0

Answer by toffino · Nov 02, 2014 at 09:14 PM

Don't forget to drag and drop your script (NetworkDoor) to your Photonview script in the inspector..

1- drag and drop your door object 2- drag and drop your network door script

It should send your variable correcly

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

21 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

Related Questions

How to instatiate two players simultaneoulsy before loading level 1 Answer

Multiplayer cant see host player C# 0 Answers

Multiplayer: client cant see host C# 0 Answers

Waiting between pingpong loops 2 Answers

using itween to move objects in the 6 degrees of freedom 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