Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Joey_pc · Aug 30, 2017 at 12:47 PM · networkingmultiplayerphotonsyncmine

Photon Sync Var

So i'm working on this project and i had a lot of fun working on it on single player but i felt that it would be good to make it multiplayer i have no experience with multiplayer so i used "Photon" ,

  • first is this a close imagine with what i have

alt text

alt text

  • then we get this you join the server and you see the person who plays for a while like a some just loged in i want people to join anytime and leave anytime

https://www.dropbox.com/home?preview=3.PNG

-so i have the codes here

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class PlayerItems : Photon.MonoBehaviour {
     
     public float hs;
     public float Health;
 
     public int RockAmouts;
     public int ActiveRocks;
     public Text Rocksa;
 
 
 
     [PunRPC]
     public void SetMyRocks(int Number){
         RockAmouts += Number;
         Debug.Log("player: "+RockAmouts);
         Rocksa.text = "" + RockAmouts;
 
     }
 
     public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
         if (stream.isWriting) {
             //we own it
             stream.SendNext (RockAmouts);
 
         } else {
             ActiveRocks = (int)stream.ReceiveNext();
         }
 
 
     }
 
 
 
 }

  • And i set the points here using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; public class ItemMine : Photon.MonoBehaviour { public PlayerItems Pt; public FindLocal fl; public bool destroya; public Sprite[] Sprites; public void OnTriggerEnter2D(Collider2D other) { if (fl.localPlayer) { PhotonView photonView = fl.localPlayer.GetComponent<PhotonView> (); if (other.tag == "Player") { fl.Itema = fl.localPlayer.GetComponent<PlayerItems> (); photonView.RPC ("SetMyRocks", PhotonTargets., 1); // Call to RPC function if (destroya == true) { PhotonNetwork.Destroy (gameObject); } } } } void OnMouseDown (){ Debug.Log("V IS BEING PRESSED!!"); // int projectileAttackRandomizer = Random.Range (1,Sprites.Length); GameObject rocks = PhotonNetwork.Instantiate("RockPoint", this.transform.position, this.transform.rotation, 0); // rocks.GetComponent<SpriteRenderer>().sprite = Sprites[projectileAttackRandomizer -= 1]; } }

  • and Finally finding my local player using System.Collections; using System.Collections.Generic; using UnityEngine; public class FindLocal : Photon.MonoBehaviour { public GameObject localPlayer; public Transform Caamera; public PlayerItems Itema; public void Update() { if (localPlayer == null) { foreach (GameObject cur in GameObject.FindGameObjectsWithTag("Player")) { Debug.Log (cur); Debug.Log ("Iterating"); if (cur.GetComponent<PhotonView> ().photonView.isMine == true) { Debug.Log ("Found local player"); localPlayer = cur; } } } if (localPlayer == null) { // Debug.Log ("Couldn't find local player"); } if (localPlayer != null) { // localPlayer.Itema if(Caamera == null){ Caamera = Camera.main.transform; } if (Itema == null) { Itema = localPlayer.GetComponent<PlayerItems> (); } } } }

1.png (90.7 kB)
2.png (106.7 kB)
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
Best Answer

Answer by Joey_pc · Sep 03, 2017 at 07:37 PM

I Fixed It By doing this #if UNITY_5 && (!UNITY_5_0 && !UNITY_5_1 && !UNITY_5_2 && !UNITY_5_3) || UNITY_6 #define UNITY_MIN_5_4 #endif using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class PlayerItems : Photon.MonoBehaviour { public float hs; public float Health; [Tooltip("The current Rocks of our player")] public int RockAmouts; public int ActiveRocks; public Text Rocksa; [PunRPC] void Update(){ this.Rocksa.text = "" + RockAmouts; } public void SetMyRocks(int Number){ RockAmouts += Number; Debug.Log("player: "+RockAmouts); } #region IPunObservable implementation public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { // We own this player: send the others our data stream.SendNext(this.RockAmouts); } else { // Network player, receive data this.RockAmouts = (int)stream.ReceiveNext(); } } #endregion }

and alt text simply drag and drop the scirpt here


a.png (15.3 kB)
Comment
Add comment · Show 1 · 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 JppetC · Mar 01, 2020 at 08:47 PM 0
Share

Thank you so much for this! Your example worked perfectly for what I was trying to accomplish! I've been searching for weeks now, your revised script worked for what I was trying to do! Thank You!

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

156 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 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 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 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 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 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 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 sync RPC function Photon Network? 1 Answer

Photon & Unity Question 0 Answers

[SOLVED] PhotonNetwork.Instantiate cannot spawn players 0 Answers

Unity - Photon OnJoinedRoom not being called 0 Answers

Sync movements Photon 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