photon with android
hey friends I made a simple pong game in android. now I want to make it multiplayer so i am using photon for that. I connect to master server then lobby and create room and status==joined i am using unity 5 and PUN simple is that working with android? now how second player join through Ip address or what? how i test in different devices? any tutorial there for photon with android i am new in unity pls help
Answer by Sykoh · Feb 18, 2016 at 05:12 PM
using UnityEngine;
using System.Collections;
public class NetworkControllerScript : MonoBehaviour {
GameObject PlayerLight;
// Use this for initialization
void Start () {
PhotonNetwork.autoJoinLobby = true;
PhotonNetwork.ConnectUsingSettings ("1");
}
// Display details to user
void OnGUI(){
GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
}
// When the lobby has been joined, join random room
void OnJoinedLobby(){
Debug.Log ("OnJoinedLobby");
PhotonNetwork.JoinRandomRoom ();
}
// If there is no room to join create one.
void OnPhotonRandomJoinFailed(){
Debug.Log ("OnPhotonRandomJoinedFailed");
PhotonNetwork.CreateRoom ( null );
}
void OnJoinedRoom(){
Debug.Log ("OnJoinedRoom");
PhotonNetwork.Instansiate("Paddle");
}
}
That's the sort of thing I would be looking at going for to start. I would then start building in being able to check the number of players in a room before joining and only joining if there is a room with 1 player and if not create you own.
You would then use "PhotonView" scripts to sync the balls transform and ridgidbody and the paddle positions. Oh and if you get that far and its a but joggy and horrible hear is a hint "Lerp is your friend".
Answer by ankitdave · Feb 22, 2016 at 06:37 AM
@Sykoh thanks for the reply it helped. but now I am stuck at one point, I have two buttons create and join, now if I clicked any of that it will bring me to my next scene which is a two_player scene, if I clicked on create spawn point of paddle is -35 and if I clicked on join it is 35 but how can I know which button I pressed in previous scene. I have added that netwok manager script in empty game object in two_player scene.
Sounds like you need to create a room list system. This is a more complicated setup and should be thought out first then any smaller aspect of the system should be asked in individual questions that can be answered clearly. Feel free to tag me in to the question once you know what you are looking for specifically.
ya sure. i have an Inputfield which user enter their name but that name i want to display on my next scene as a label or text then what i have to do?
Your answer
![](https://koobas.hobune.stream/wayback/20220612064656im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
UNET is that join multiple matches possible ? 0 Answers
showroom with background music 0 Answers
What is the purpose of the broadcast data sent/received from NetworkDiscovery? 0 Answers
The PlayerPrefab is empty on the Network Manager error is show up on online scene 0 Answers
Multiplayer First Person Game 0 Answers