Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityStandardAssets.Characters.FirstPerson;
- public class OnJoinInstantiate : Photon.MonoBehaviour
- {
- public Transform ObjectToInstantiate;
- public Transform ObjectToInstantiatePROP;
- public bool InstantiateSceneObjects = false;
- public GameObject newObj; // not used but to show that you get the GO as return;
- private MouseLook cameraScript1;
- private MouseLook cameraScript2;
- private CharacterController ControllerScript; //Can't find it herepr
- private FirstPersonController firstpersoncontroller;
- private Transform thisTransform;
- private GameObject thisObject;
- private GameObject camera;
- private CharacterController ControllerScriptPROP; //Can't find it herepr
- private FirstPersonController firstpersoncontrollerPROP;
- private Transform thisTransformPROP;
- private GameObject thisObjectPROP;
- private GameObject cameraPROP;
- private MouseLook cameraScript1PROP;
- private MouseLook cameraScript2PROP;
- void Awake(){
- thisTransform = ObjectToInstantiate.transform;
- thisObject = ObjectToInstantiate.gameObject;
- camera = ObjectToInstantiate.FindChild("Main Camera").gameObject;
- cameraScript1 = ObjectToInstantiate.GetComponent<MouseLook> ();
- cameraScript2 = ObjectToInstantiate.GetComponent<MouseLook> ();
- ControllerScript = ObjectToInstantiate.GetComponent<CharacterController> ();
- firstpersoncontroller = ObjectToInstantiate.GetComponent<FirstPersonController> ();
- thisTransformPROP = ObjectToInstantiatePROP.transform;
- thisObjectPROP = ObjectToInstantiatePROP.gameObject;
- cameraPROP = ObjectToInstantiatePROP.FindChild("Main Camera").gameObject;
- cameraScript1PROP = ObjectToInstantiatePROP.GetComponent<MouseLook> ();
- cameraScript2PROP = ObjectToInstantiatePROP.GetComponent<MouseLook> ();
- ControllerScriptPROP = ObjectToInstantiatePROP.GetComponent<CharacterController> ();
- firstpersoncontrollerPROP = ObjectToInstantiatePROP.GetComponent<FirstPersonController> ();
- if (photonView.isMine) {
- if(SelectTeam.team == 0){
- cameraPROP.GetComponent<Camera>().enabled = true;
- cameraPROP.GetComponent<AudioListener>().enabled = true;
- ControllerScriptPROP.enabled = true;
- firstpersoncontrollerPROP.enabled = true;
- }else if(SelectTeam.team == 1){
- camera.GetComponent<Camera>().enabled = true;
- camera.GetComponent<AudioListener>().enabled = true;
- ControllerScript.enabled = true;
- firstpersoncontroller.enabled = true;
- }
- }
- else{
- camera.GetComponent<Camera>().enabled = false;
- camera.GetComponent<AudioListener>().enabled = false;
- ControllerScript.enabled = false;
- firstpersoncontroller.enabled = false;
- cameraPROP.GetComponent<Camera>().enabled = false;
- cameraPROP.GetComponent<AudioListener>().enabled = false;
- ControllerScriptPROP.enabled = false;
- firstpersoncontrollerPROP.enabled = true;
- }
- thisObject.name = PhotonNetwork.playerName;
- }
- public void OnJoinedRoom()
- {
- Vector3 pos = this.gameObject.transform.position;
- pos.x += PhotonNetwork.player.ID;
- if (!InstantiateSceneObjects)
- {
- if(SelectTeam.team == 0){
- newObj = PhotonNetwork.Instantiate(ObjectToInstantiatePROP.name, pos, Quaternion.identity, 0, null);
- }else if(SelectTeam.team == 1){
- newObj = PhotonNetwork.Instantiate(ObjectToInstantiate.name, pos, Quaternion.identity, 0, null);
- }
- // anything you do with newObj locally is not reflected on the other clients.
- // you can add a script to the Prefab to do some instantiation in Awake() and you can call RPCs on newObj now.
- }
- else
- {
- if(SelectTeam.team == 0){
- newObj = PhotonNetwork.InstantiateSceneObject(ObjectToInstantiatePROP.name, pos, Quaternion.identity, 0, null);
- }else if(SelectTeam.team == 1){
- newObj = PhotonNetwork.InstantiateSceneObject(ObjectToInstantiate.name, pos, Quaternion.identity, 0, null);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement