Advertisement
Guest User

Untitled

a guest
Mar 28th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. using Photon.Pun;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class SpawnMultiplayer : MonoBehaviour
  7. {
  8. public GameObject prefab;
  9. private static float spawnYPosition;
  10. float spawnzposition;
  11. PhotonView photonView;
  12. bool SpawnOnce;
  13.  
  14. void Start()
  15. {
  16. spawnYPosition = 0f;
  17. photonView = GetComponent<PhotonView>();
  18. SpawnOnce = true;
  19.  
  20. }
  21.  
  22. void SpawnColumn()
  23. {
  24. //Your current code
  25. // spawnYPosition = Randwom.Ranye(-3.36f, 2.98f);
  26.  
  27. spawnYPosition = Random.Range(-3.36f, 2.98f);
  28. Instantiate(prefab, new Vector2(9, spawnYPosition), Quaternion.identity);
  29. photonView.RPC("RPC_SpawnColumn", RpcTarget.Others, new Vector3(9, spawnYPosition));
  30. print("SpawnOnce Should be false");
  31. SpawnOnce = false;
  32. }
  33.  
  34. [PunRPC]
  35. void RPC_SpawnColumn(Vector3 position)
  36. {
  37. // Instantiate(prefab, position, Quaternion.identity);
  38. //Debug.Log("THIS IS SPAWNYPOSITION" + spawnYPosition);
  39.  
  40. //Instantiate(prefab, new Vector2(9, spawnYPosition), Quaternion.identity);
  41. Instantiate(prefab, position, Quaternion.identity);
  42. }
  43.  
  44. private void OnTriggerEnter2D(Collider2D collision)
  45. {
  46. //print("Are we here");
  47. if (collision.GetComponent<ColumnsMultiplayer>() != null)
  48. {
  49.  
  50. print("Or are we here");
  51. if (SpawnOnce)
  52. {
  53. spawnYPosition = Random.Range(-3.36f, 2.98f);
  54.  
  55. Debug.Log("THIS IS IN ON TRIGGER" + spawnYPosition);
  56. //spawnzposition = 2f;
  57. photonView.RPC("RPC_SpawnColumn", RpcTarget.Others,new Vector3(9, spawnYPosition)); // this is
  58. Debug.Log("THIS IS afert TRIGGER" + spawnYPosition);
  59. }
  60. //SpawnColumn();
  61.  
  62. SpawnOnce = false;
  63.  
  64.  
  65. }
  66. }
  67.  
  68.  
  69. private void OnTriggerExit2D(Collider2D collision)
  70. {
  71. print("Did we exit");
  72. if (collision.GetComponent<ColumnsMultiplayer>() != null)
  73. {
  74. print("make sure we exited");
  75. SpawnOnce = true;
  76. }
  77. }
  78.  
  79. private void Update()
  80. {
  81. print(SpawnOnce);
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement