Помогите с PhotonNetwork.RPC(Для удаления объектов)
Вот код и по нажатию кнопки Игроком в определенной зоне/точке объект должен удаляться.
if (target.position.x == animatoric.position.x && target.position.z == animatoric.position.z)
{
Warning_Animal.SetActive(true);
if (Input.GetKeyDown(KeyCode.E))
{
destroy1.void OnClick();
PhotonNetwork.Instantiate(Animal_Game.name, animalspawn.position, animalspawn.rotation, 0);
animal = animal + 1;
}
}
else
{
Warning_Animal.SetActive(false);
}
Вот код с RPC ошибки не выдает, но объект не удаляется
using UnityEngine;
using System.Collections;
/// <summary>
/// Implements OnClick to destroy the GameObject it's attached to. Optionally a RPC is sent to do this.
/// </summary>
/// <remarks>
/// Using an RPC to Destroy a GameObject allows any player to Destroy a GameObject. But it might cause errors.
/// RPC and the Instantiated GameObject are not fully linked on the server. One might stick in the server witout
/// the other.
///
/// A buffered RPC gets cleaned up when the sending player leaves the room. This means, the RPC gets lost.
///
/// Vice versus, a GameObject Instantiate might get cleaned up when the creating player leaves a room.
/// This way, the GameObject that a RPC targets might become lost.
///
/// It makes sense to test those cases. Many are not breaking errors and you just have to be aware of them.
///
/// Gets OnClick() calls by InputToEvent class attached to a camera.
/// </remarks>
[RequireComponent(typeof(PhotonView))]
public class Destroy1 : Photon.MonoBehaviour
{
public bool DestroyByRpc;
public GameObject Cell;
public void OnClick()
{
if (!DestroyByRpc)
{
PhotonNetwork.Destroy(Cell);
}
else
{
this.photonView.RPC("DestroyRpc", PhotonTargets.AllBuffered);
}
}
[PunRPC]
public IEnumerator DestroyRpc()
{
GameObject.Destroy(Cell);
yield return 0; // if you allow 1 frame to pass, the object's OnDestroy() method gets called and cleans up references.
PhotonNetwork.UnAllocateViewID(this.photonView.viewID);
}
}