Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityStandardAssets.Characters.FirstPerson;
  4.  
  5. public class OnJoinInstantiate : Photon.MonoBehaviour
  6. {
  7. public Transform ObjectToInstantiate;
  8. public Transform ObjectToInstantiatePROP;
  9. public bool InstantiateSceneObjects = false;
  10.  
  11. public GameObject newObj; // not used but to show that you get the GO as return;
  12. private MouseLook cameraScript1;
  13. private MouseLook cameraScript2;
  14. private CharacterController ControllerScript; //Can't find it herepr
  15. private FirstPersonController firstpersoncontroller;
  16. private Transform thisTransform;
  17. private GameObject thisObject;
  18. private GameObject camera;
  19.  
  20. private CharacterController ControllerScriptPROP; //Can't find it herepr
  21. private FirstPersonController firstpersoncontrollerPROP;
  22. private Transform thisTransformPROP;
  23. private GameObject thisObjectPROP;
  24. private GameObject cameraPROP;
  25. private MouseLook cameraScript1PROP;
  26. private MouseLook cameraScript2PROP;
  27.  
  28. void Awake(){
  29. thisTransform = ObjectToInstantiate.transform;
  30. thisObject = ObjectToInstantiate.gameObject;
  31. camera = ObjectToInstantiate.FindChild("Main Camera").gameObject;
  32.  
  33. cameraScript1 = ObjectToInstantiate.GetComponent<MouseLook> ();
  34. cameraScript2 = ObjectToInstantiate.GetComponent<MouseLook> ();
  35. ControllerScript = ObjectToInstantiate.GetComponent<CharacterController> ();
  36. firstpersoncontroller = ObjectToInstantiate.GetComponent<FirstPersonController> ();
  37.  
  38.  
  39. thisTransformPROP = ObjectToInstantiatePROP.transform;
  40. thisObjectPROP = ObjectToInstantiatePROP.gameObject;
  41. cameraPROP = ObjectToInstantiatePROP.FindChild("Main Camera").gameObject;
  42.  
  43. cameraScript1PROP = ObjectToInstantiatePROP.GetComponent<MouseLook> ();
  44. cameraScript2PROP = ObjectToInstantiatePROP.GetComponent<MouseLook> ();
  45. ControllerScriptPROP = ObjectToInstantiatePROP.GetComponent<CharacterController> ();
  46. firstpersoncontrollerPROP = ObjectToInstantiatePROP.GetComponent<FirstPersonController> ();
  47.  
  48.  
  49. if (photonView.isMine) {
  50. if(SelectTeam.team == 0){
  51. cameraPROP.GetComponent<Camera>().enabled = true;
  52. cameraPROP.GetComponent<AudioListener>().enabled = true;
  53. ControllerScriptPROP.enabled = true;
  54. firstpersoncontrollerPROP.enabled = true;
  55. }else if(SelectTeam.team == 1){
  56. camera.GetComponent<Camera>().enabled = true;
  57. camera.GetComponent<AudioListener>().enabled = true;
  58. ControllerScript.enabled = true;
  59. firstpersoncontroller.enabled = true;
  60. }
  61. }
  62.  
  63. else{
  64. camera.GetComponent<Camera>().enabled = false;
  65. camera.GetComponent<AudioListener>().enabled = false;
  66. ControllerScript.enabled = false;
  67. firstpersoncontroller.enabled = false;
  68. cameraPROP.GetComponent<Camera>().enabled = false;
  69. cameraPROP.GetComponent<AudioListener>().enabled = false;
  70. ControllerScriptPROP.enabled = false;
  71. firstpersoncontrollerPROP.enabled = true;
  72.  
  73. }
  74.  
  75. thisObject.name = PhotonNetwork.playerName;
  76.  
  77. }
  78. public void OnJoinedRoom()
  79. {
  80. Vector3 pos = this.gameObject.transform.position;
  81. pos.x += PhotonNetwork.player.ID;
  82.  
  83. if (!InstantiateSceneObjects)
  84. {
  85. if(SelectTeam.team == 0){
  86. newObj = PhotonNetwork.Instantiate(ObjectToInstantiatePROP.name, pos, Quaternion.identity, 0, null);
  87. }else if(SelectTeam.team == 1){
  88. newObj = PhotonNetwork.Instantiate(ObjectToInstantiate.name, pos, Quaternion.identity, 0, null);
  89. }
  90.  
  91. // anything you do with newObj locally is not reflected on the other clients.
  92. // you can add a script to the Prefab to do some instantiation in Awake() and you can call RPCs on newObj now.
  93. }
  94. else
  95. {
  96. if(SelectTeam.team == 0){
  97. newObj = PhotonNetwork.InstantiateSceneObject(ObjectToInstantiatePROP.name, pos, Quaternion.identity, 0, null);
  98. }else if(SelectTeam.team == 1){
  99. newObj = PhotonNetwork.InstantiateSceneObject(ObjectToInstantiate.name, pos, Quaternion.identity, 0, null);
  100. }
  101.  
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement