I use Photon to create a multiplayer game in my game, to ensure that one player does not control them all, when you appear on the client side, he activates your scripts / camera so that you can see and move around.
Although I canβt think of a way to solve this problem, since I donβt know how to enable / disable child components or enable a child child.
I want to enable this through scripts
http://imgur.com/ZntA8Qx
and this is
http://imgur.com/Nd0Ktoy
My script:
using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour {
public Camera standByCamera;
void Start () {
Connect();
}
void Connect() {
Debug.Log("Attempting to connect to Master...");
PhotonNetwork.ConnectUsingSettings("0.0.1");
}
void OnGUI() {
GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
}
void OnConnectedToMaster() {
Debug.Log("Joined Master Successfully.");
Debug.Log("Attempting to connect to a random room...");
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed(){
Debug.Log("Join Failed: No Rooms.");
Debug.Log("Creating Room...");
PhotonNetwork.CreateRoom(null);
}
void OnJoinedRoom() {
Debug.Log("Joined Successfully.");
SpawnMyPlayer();
}
void SpawnMyPlayer() {
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("Body", Vector3.zero, Quaternion.identity, 0);
standByCamera.enabled = false;
((MonoBehaviour)myPlayerGO.GetComponent("Movement")).enabled = true;
}
}
monobehaivour - ,
, , -, , , , , .
, , , , , , myPlayerGO Game, .
, , , , .
, , , .
user4540474