Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 DarkFire1 · Jul 14, 2015 at 09:22 AM · networkingvariablesrpcpuninstances

Problem storing GameObject reference in script - PUN

Hello!

I'm currently networking with the newest version of PUN, and I'm quickly running into trouble finding a way to access the player's attached scripts.

Some background - The game is a 2D card game. When each player joins, I instantiate their deck, junk pile, hand interface, etc. through PUN using PhotonNetwork.Instantiate.

However, I need to spawn the battlefield after both players join. I then need to assign references from the spots in the battlefield where cards can be played to public variables on both players.

Note: The battlefield consists of three smaller fields that I'm calling Realms.

This is where the problems begin. My NetworkController script can't seem to store a reference to Player1, even though I've tried both static and non-static variables. So when the field is made, neither Player1 nor Player2 receive the variable assignments.

I've tried GameObject.Find but, even though I set the name of each object after it is instantiated, the Player still does not recieve the assignment.

Here's the important part of the script.

         GameObject re1 = PhotonNetwork.Instantiate ("Realm1", Vector3.zero, Quaternion.identity, 0);
         GameObject re2 = PhotonNetwork.Instantiate ("Realm2", Vector3.zero, Quaternion.identity, 0);
         GameObject re3 = PhotonNetwork.Instantiate ("Realm3", Vector3.zero, Quaternion.identity, 0);
         AddToRealms (re1, re2, re3); //Function that adds items to List.
         //The items are then randomized and put in predetermined transforms.
 //In the randomizing code, re1 - re3 are turned into realm1 - realm3.
         realm1.name = "Realm1";
         realm2.name = "Realm2";
         realm3.name = "Realm3";

 GameObject p1 = GameObject.Find ("Player1");
         GameObject p2 = GameObject.Find ("Player2");
         p1.GetComponent<PhotonView>().RPC ("TheSCode", PhotonTargets.AllBuffered);
         p2.GetComponent<PhotonView>().RPC ("TheSCode", PhotonTargets.AllBuffered);


In another script:

 [PunRPC]
     public void TheSCode (){
 
         if (playerInt == 1) {
         
             GameObject q1 = GameObject.Find ("Realm1/S1"); 
             s1 = q1;
             GameObject q2 = GameObject.Find ("Realm1/S2"); 
             s2 = q2;
             GameObject q3 = GameObject.Find ("Realm1/S3"); 
             s3 = q3;
             GameObject q4 = GameObject.Find ("Realm2/S1"); 
             s12 = q4;
             GameObject q5 = GameObject.Find ("Realm2/S2"); 
             s22 = q5;
             GameObject q6 = GameObject.Find ("Realm2/S3"); 
             s32 = q6;
             GameObject q7 = GameObject.Find ("Realm3/S1"); 
             s13 = q7;
             GameObject q8 = GameObject.Find ("Realm3/S2"); 
             s23 = q8;
             GameObject q9 = GameObject.Find ("Realm3/S3"); 
             s33 = q9;
         }else if (playerInt == 2) {
             
             GameObject q1 = GameObject.Find ("Realm1/2S1"); 
             s1 = q1;
             GameObject q2 = GameObject.Find ("Realm1/2S2"); 
             s2 = q2;
             GameObject q3 = GameObject.Find ("Realm1/2S3"); 
             s3 = q3;
             GameObject q4 = GameObject.Find ("Realm2/2S1"); 
             s12 = q4;
             GameObject q5 = GameObject.Find ("Realm2/2S2"); 
             s22 = q5;
             GameObject q6 = GameObject.Find ("Realm2/2S3"); 
             s32 = q6;
             GameObject q7 = GameObject.Find ("Realm3/2S1"); 
             s13 = q7;
             GameObject q8 = GameObject.Find ("Realm3/2S2"); 
             s23 = q8;
             GameObject q9 = GameObject.Find ("Realm3/2S3"); 
             s33 = q9;
   
         }
 
 
     }



s1 - s33 are what I need to set. I'm incredibly confused, as everything I try fails when it comes to resolving this. Any help would be greatly appreciated!

Comment
Add comment
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

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

2 People are following this question.

avatar image avatar image

Related Questions

Changing a variable in another script over the network 1 Answer

How to pass a variable to a late-joining player without syncvars? / What function gets called on a new player connect? 1 Answer

Send a Pause RPC on OnApplicationPause 1 Answer

RPC or Synchronization ? 1 Answer

Multiplayer Moving Bullet 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