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 Jackmawer · Apr 09, 2015 at 04:27 AM · c#photon

Issues with PhotonView

I've been searching all day so far, and I could find a solution. Here's some code that connects to the Photon servers, joins a room and spawns a player. On the player, there is a RigidbodyFirstPersonController script that I want to disable for remote players so a user can only control their own player. Here's the code so far: using UnityEngine; using System.Collections; using UnityStandardAssets.Characters.FirstPerson;

 public class WorldNetworking : MonoBehaviour {
     public string playerPrefab;
 
     // Use this for initialization
     void Start()
     {
         PhotonNetwork.ConnectUsingSettings("0.1");
     }
     
     void OnGUI()
     {
         GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
     }
 
     void OnJoinedLobby ()
     {
         RoomOptions roomOptions = new RoomOptions() { isVisible = true, maxPlayers = 500 };
         PhotonNetwork.JoinOrCreateRoom("Default", roomOptions, TypedLobby.Default);
     }
 
     void OnPhotonJoinRoomFailed (object[] reasonForFailure)
     {
         //Example: void OnPhotonJoinRoomFailed(object[] codeAndMsg) { // codeAndMsg[0] is int ErrorCode. codeAndMsg[1] is string debug msg. } 
         Debug.Log ("Failed to join room with code " + reasonForFailure[0] + " message " + reasonForFailure[1] + ". Retrying.");
         OnJoinedLobby ();//Try again.
     }
 
     void OnJoinedRoom() 
     {
         SpawnPlayer ();
     }
     
     private void SpawnPlayer()
     {
         Debug.Log ("SpawnPlayer");
 
         GameObject MyPlayer = PhotonNetwork.Instantiate(playerPrefab, new Vector3(2530f, 8f, 2510f), Quaternion.identity, 0);
 
         PhotonView myPhotonView;
         myPhotonView = MyPlayer.GetComponent(PhotonView);
         if (myPhotonView.isMine) {
             RigidbodyFirstPersonController playerControl = MyPlayer.GetComponent<RigidbodyFirstPersonController> ();
             playerControl.enabled = true;
         }
     }
 
     // Update is called once per frame
     void Update () {
     
     }
 }
 

However, this throws the errors

 Assets/WorldNetworking.cs(44,54): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected

 Assets/WorldNetworking.cs(44,41): error CS1502: The best overloaded method match for `UnityEngine.GameObject.GetComponent(System.Type)' has some invalid arguments.

 Assets/WorldNetworking.cs(44,41): error CS1503: Argument `#1' cannot convert `object' expression to type `System.Type' 

I then changed PhotonView myPhotonView; myPhotonView = MyPlayer.GetComponent(PhotonView); to

 new PhotonView myPhotonView = MyPlayer.GetComponent(PhotonView);

which resulted in

 Assets/WorldNetworking.cs(43,43): error CS1525: Unexpected symbol `myPhotonView', expecting `(', `)', `,', `;', `[', `{', or `<operator>'

I am left clueless, and hoping someone on this community could help.

Comment
Add comment · Show 1
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 Jackmawer · Apr 09, 2015 at 10:28 AM 0
Share

I might be able to fix this by changing the code to

 myPhotonView = new PhotonView;
 myPhotonView = $$anonymous$$yPlayer.GetComponent(PhotonView);


But I haven't tested it as of yet.

EDIT: This didn't work.

2 Replies

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

Answer by Jackmawer · Apr 09, 2015 at 07:50 PM

I tried hbalint1's answer and found that it had another error:

 The type arguments for method `UnityEngine.GameObject.GetComponent<T>()' cannot be inferred from the usage. Try specifying the type arguments explicitly
 

so, I changed the code to

 PhotonView myPhotonView;
         myPhotonView = MyPlayer.GetComponent<PhotonView>();

and it worked without errors. Thanks for your help, hbalint1!

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
avatar image
0

Answer by hbalint1 · Apr 09, 2015 at 03:23 PM

change

 myPhotonView = MyPlayer.GetComponent(PhotonView);

to

 myPhotonView = MyPlayer.GetComponent<PhotonView>();
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

"PhotonView with ID 1001 has no method "ChatMessage" that takes 2 argument(s): String, Object[]" ... But it has.... 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

PUN player referencing 1 Answer

How synchronizate my Timer using Photon? 3 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