Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Photon.Pun;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SpawnMultiplayer : MonoBehaviour
- {
- public GameObject prefab;
- private static float spawnYPosition;
- float spawnzposition;
- PhotonView photonView;
- bool SpawnOnce;
- void Start()
- {
- spawnYPosition = 0f;
- photonView = GetComponent<PhotonView>();
- SpawnOnce = true;
- }
- void SpawnColumn()
- {
- //Your current code
- // spawnYPosition = Randwom.Ranye(-3.36f, 2.98f);
- spawnYPosition = Random.Range(-3.36f, 2.98f);
- Instantiate(prefab, new Vector2(9, spawnYPosition), Quaternion.identity);
- photonView.RPC("RPC_SpawnColumn", RpcTarget.Others, new Vector3(9, spawnYPosition));
- print("SpawnOnce Should be false");
- SpawnOnce = false;
- }
- [PunRPC]
- void RPC_SpawnColumn(Vector3 position)
- {
- // Instantiate(prefab, position, Quaternion.identity);
- //Debug.Log("THIS IS SPAWNYPOSITION" + spawnYPosition);
- //Instantiate(prefab, new Vector2(9, spawnYPosition), Quaternion.identity);
- Instantiate(prefab, position, Quaternion.identity);
- }
- private void OnTriggerEnter2D(Collider2D collision)
- {
- //print("Are we here");
- if (collision.GetComponent<ColumnsMultiplayer>() != null)
- {
- print("Or are we here");
- if (SpawnOnce)
- {
- spawnYPosition = Random.Range(-3.36f, 2.98f);
- Debug.Log("THIS IS IN ON TRIGGER" + spawnYPosition);
- //spawnzposition = 2f;
- photonView.RPC("RPC_SpawnColumn", RpcTarget.Others,new Vector3(9, spawnYPosition)); // this is
- Debug.Log("THIS IS afert TRIGGER" + spawnYPosition);
- }
- //SpawnColumn();
- SpawnOnce = false;
- }
- }
- private void OnTriggerExit2D(Collider2D collision)
- {
- print("Did we exit");
- if (collision.GetComponent<ColumnsMultiplayer>() != null)
- {
- print("make sure we exited");
- SpawnOnce = true;
- }
- }
- private void Update()
- {
- print(SpawnOnce);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement