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 Jaidan · Feb 17, 2015 at 03:33 PM · c#photon

Sync game objects across network Photon C#

How would i have it so that both of the players in my game can see moving objects, because i have it so the players can see each other fine and when the move on one instance of the game the other player can see it, but how would i have this done with game objects. I have it so that the players can pick up objects but when a player picks up an object on one screen/game the other player does not see this on there game. Here is some of my code:

 using UnityEngine;
 using System.Collections;
 
 public class NetworkCharacter : Photon.MonoBehaviour {
 
     Vector3 realPosition = Vector3.zero;
     Quaternion realRotation = Quaternion.identity;
 
     void Update(){
 
         if (photonView.isMine) {
 
         }
         else {
             transform.position = Vector3.Lerp (transform.position, this.realPosition, 0.1f);
             transform.rotation = Quaternion.Lerp (transform.rotation, this.realRotation, 0.1f);
         }
 
     }
 
     void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
 
         if (stream.isWriting) {
 
             stream.SendNext(transform.position);
             stream.SendNext(transform.rotation);
 
         }
         else {
 
             this.realPosition = (Vector3) stream.ReceiveNext();
             this.realRotation = (Quaternion) stream.ReceiveNext();
         }
     }
 }


 using UnityEngine;
 using System.Collections;
 
 public class NetworkManager : MonoBehaviour {
 
     public GameObject standByCamera;
 
     void Start () {
         PhotonNetwork.ConnectUsingSettings ("0.0.1");
     }
     void OnGUI () {
         UnityEngine.GUILayout.Label ( PhotonNetwork.connectionStateDetailed.ToString() );
     }
     void OnJoinedLobby () {
         PhotonNetwork.JoinRandomRoom ();
     }
     void OnPhotonRandomJoinFailed () {
         PhotonNetwork.CreateRoom ( "MAIN" );
     }
     void OnJoinedRoom () {
 
         GameObject myPlayerGO = PhotonNetwork.Instantiate ("PlayerController", Vector3.zero, Quaternion.identity, 0);
         GameObject _minimap = PhotonNetwork.Instantiate ("MinimapCamera", new Vector3(0, 100, 0), Quaternion.Euler(90 ,0 ,0), 0);
         GameObject box = PhotonNetwork.Instantiate ("FlatCube", new Vector3(5, 1, 5), Quaternion.identity, 0);
 
         standByCamera.SetActive (false);
 
         myPlayerGO.transform.FindChild ("Main Camera").gameObject.SetActive(true);
         myPlayerGO.transform.FindChild ("MinimapCamera").gameObject.SetActive(true);
         ((MonoBehaviour)myPlayerGO.GetComponent ("FirstPersonController")).enabled = true;
         ((MonoBehaviour)box.GetComponent ("Pickupable")).enabled = true;
     }
     
 }


I have the Network character for my player characters so they can see each other

I have the Network manager to setup the games

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MidgardDev · Feb 17, 2015 at 04:54 PM

The first thing coming to my mind would be adding a PhotonView component to every GameObject you want to be able to track on both server and client.

Comment
Add comment · Show 7 · 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 Jaidan · Feb 17, 2015 at 05:33 PM 0
Share

Yeah i have done that, but the objects still dont sync :/

avatar image Jaidan · Feb 17, 2015 at 05:33 PM 0
Share

but thanks for the idea :D

avatar image MidgardDev · Feb 17, 2015 at 05:35 PM 0
Share

Are you serializing its position over the network?

avatar image Jaidan · Feb 17, 2015 at 05:59 PM 0
Share

How would i do that?

avatar image MidgardDev · Feb 17, 2015 at 06:05 PM 0
Share

You're already serializing the player's position over the network, just use the same method ;)

Show more comments

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

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Photon synchronization 1 Answer

Photon Networking Spawn player 2 0 Answers

Unable to network remove object 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