How to all players can destroy object?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class PhotonSerialize : MonoBehaviourPunCallbacks
{
public Camera mycam;
public GameObject myPrefab;
Vector3 spawnposition;
public PhotonView pv;
public PhotonView pvController;
public GameObject ManagerBricks;
public MasterInstantiate mstInstan;
// public MapController mapCtrl;
public GameObject MaSterObj;
int viewID;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
MaSterObj = GameObject.Find("MapControl");
mstInstan = MaSterObj.GetComponent<MasterInstantiate>();
if (Input.GetMouseButtonDown(0))
{
if (pv.IsMine)
{
// mapCtrl.CameraPlayer = mycam;
//Chunky();
mstInstan.currentCamera = mycam;
Ray ray;
RaycastHit hit;
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 100.0f))
{
if (hit.collider.tag == "Voxel")
{
spawnposition = new Vector3(Mathf.RoundToInt(hit.point.x + hit.normal.x / 2), Mathf.RoundToInt(hit.point.y + hit.normal.y / 2), Mathf.RoundToInt(hit.point.z + hit.normal.z / 2));
pv.RPC("BuildThis", RpcTarget.All);
}
else if (hit.collider.tag == "Ground")
{
spawnposition = new Vector3(Mathf.RoundToInt(hit.point.x + hit.normal.x / 2), Mathf.RoundToInt(hit.point.y + hit.normal.y / 2), Mathf.RoundToInt(hit.point.z + hit.normal.z / 2));
pv.RPC("BuildThis", RpcTarget.All);
}
}
}
}
if (Input.GetMouseButtonDown(1))
{
if (pv.IsMine)
{
//estroyOb();
mstInstan.currentCamera = mycam;
Ray ray;
RaycastHit hit;
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 100.0f))
{
if (hit.collider.tag == "Voxel")
{
//mstInstan.spawnpositionMi = spawnposition;
// pvController.RPC("DestroyThis", RpcTarget.All);
// viewID = hit.collider.GetComponent<PhotonView>().ViewID;
// pv.RPC("DestroyThis", RpcTarget.MasterClient, viewID);
PhotonNetwork.Destroy(hit.transform.gameObject);
}
}
}
}
}
[PunRPC]
public void BuildThis()
{
PhotonNetwork.Instantiate(myPrefab.name, spawnposition, Quaternion.identity);
}
[PunRPC]
public void DestroyThis()
{
PhotonNetwork.Destroy(PhotonView.Find(viewID).gameObject);
}
}
Well, the one who built it can break his object and the rest can't