PhotonNetwork.Destroy C# (CSharp) Method

Destroy() public static method

Destroys given GameObject. This GameObject must've been instantiated using PhotonNetwork.Instantiate and must have a PhotonView at it's root. This has the same effect as calling Destroy by passing an attached PhotonView from this GameObject
public static Destroy ( GameObject go ) : void
go GameObject
return void
    public static void Destroy(GameObject go)
    {
        PhotonView view = go.GetComponent<PhotonView>();
        if (view == null)
        {
            Debug.LogError("Cannot call Destroy(GameObject go); on the gameobject \"" + go.name + "\" as it has no PhotonView attached.");
        }
        else if (view.isMine)
        {
            int ID = networkingPeer.GetInstantiatedObjectsId(go);
            if (ID <= 0)
            {
                Debug.LogError("Use PhotonNetwork.Destroy() only on GameObjects created with PhotonNetwork.Instantiate(). GameObject not destroyed: " + go);
            }
            else
            {
                networkingPeer.RemoveInstantiatedGO(go, false); //Success
            }
        }
        else
        {
            Debug.LogError("Cannot call Destroy(GameObject go); on the gameobject \"" + go.name + "\" as we don't control it (Owner: " + view.owner + ").");
        }
    }

Same methods

PhotonNetwork::Destroy ( PhotonView view ) : void

Usage Example

Ejemplo n.º 1
0
        IEnumerator DestroyGameObject(GameObject objectToDestroy, float waitTime)
        {
            yield return(new WaitForSeconds(waitTime));

            PhotonNetwork.Destroy(objectToDestroy);
        }
All Usage Examples Of PhotonNetwork::Destroy