такую ошибку выдаёт "Failed to 'network-remove' GameObject. Client is neither owner nor master Client taking over for owner who left"
это нужно для инвертаря
вот скрипт
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class Inventory : Photon.MonoBehaviour {
// Use this for initialization
public List<Item> list;
GameObject cam;
public GameObject inventory;
public GameObject contener;
void OnEnable()
{
inventory = GameObject.FindGameObjectWithTag("Inventar");
if (!cam && Camera.main)
cam = GameObject.FindGameObjectWithTag("MainCamera");
// Your characters's camera tag
if (!cam)
{
Debug.Log("Please assign a camera to the ThirdPersonCamera script.");
enabled = false;
}
cam.GetComponent<Camera>();
}
void Start () {
list = new List<Item>();
inventory.SetActive(false);
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonUp(1))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Item item = hit.collider.GetComponent<Item>();
if (item != null)
{
list.Add(item);
PhotonNetwork.Destroy(hit.collider.gameObject);
}
}
}
if(Input.GetKeyUp(KeyCode.I))
{
if (inventory.activeSelf)
{
inventory.SetActive(false);
for (int i = 0; i < inventory.transform.childCount; i++)
{
if (inventory.transform.GetChild(i).transform.childCount > 0)
{
Destroy(inventory.transform.GetChild(i).transform.GetChild(0).gameObject);
}
}
}
else
{
inventory.SetActive(true);
int count = list.Count;
for (int i = 0; i < count; i++)
{
Item it = list[i];
if(inventory.transform.childCount>=i)
{
GameObject img = Instantiate(contener);
img.transform.SetParent(inventory.transform.GetChild(i).transform);
img.GetComponent<Image>().sprite =Resources.Load<Sprite>(it.sprite);
img.AddComponent<Button>().onClick.AddListener(() => remove(it, img));
}
else break;
}
}
}
}
void remove(Item it, GameObject obj)
{
GameObject newo = Resources.Load<GameObject>(it.prefab);
PhotonNetwork.InstantiateSceneObject(newo.name,Vector3.up,Quaternion.identity,0,null);
newo.transform.position = transform.position + transform.forward + transform.up;
Destroy(obj);
list.Remove(it);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class Inventory : Photon.MonoBehaviour {
// Use this for initialization
public List<Item> list;
GameObject cam;
public GameObject inventory;
public GameObject contener;
void OnEnable()
{
inventory = GameObject.FindGameObjectWithTag("Inventar");
if (!cam && Camera.main)
cam = GameObject.FindGameObjectWithTag("MainCamera");
// Your characters's camera tag
if (!cam)
{
Debug.Log("Please assign a camera to the ThirdPersonCamera script.");
enabled = false;
}
cam.GetComponent<Camera>();
}
void Start () {
list = new List<Item>();
inventory.SetActive(false);
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonUp(1))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Item item = hit.collider.GetComponent<Item>();
if (item != null)
{
list.Add(item);
PhotonNetwork.Destroy(hit.collider.gameObject);
}
}
}
if(Input.GetKeyUp(KeyCode.I))
{
if (inventory.activeSelf)
{
inventory.SetActive(false);
for (int i = 0; i < inventory.transform.childCount; i++)
{
if (inventory.transform.GetChild(i).transform.childCount > 0)
{
Destroy(inventory.transform.GetChild(i).transform.GetChild(0).gameObject);
}
}
}
else
{
inventory.SetActive(true);
int count = list.Count;
for (int i = 0; i < count; i++)
{
Item it = list[i];
if(inventory.transform.childCount>=i)
{
GameObject img = Instantiate(contener);
img.transform.SetParent(inventory.transform.GetChild(i).transform);
img.GetComponent<Image>().sprite =Resources.Load<Sprite>(it.sprite);
img.AddComponent<Button>().onClick.AddListener(() => remove(it, img));
}
else break;
}
}
}
}
void remove(Item it, GameObject obj)
{
GameObject newo = Resources.Load<GameObject>(it.prefab);
PhotonNetwork.InstantiateSceneObject(newo.name,Vector3.up,Quaternion.identity,0,null);
newo.transform.position = transform.position + transform.forward + transform.up;
Destroy(obj);
list.Remove(it);
}
}
пробывал с RPC, тоже не получается, нигде не синхронизируется
Синтаксис:
Используется csharp
Item item = hit.collider.GetComponent<Item>();
if (item != null)
{
list.Add(item);
ty = hit.collider.gameObject;
GetComponentInParent<PhotonView>().RPC("coobik", PhotonTargets.All, null);
}
[PunRPC]
private void coobik()
{
PhotonNetwork.Destroy(ty);
}
if (item != null)
{
list.Add(item);
ty = hit.collider.gameObject;
GetComponentInParent<PhotonView>().RPC("coobik", PhotonTargets.All, null);
}
[PunRPC]
private void coobik()
{
PhotonNetwork.Destroy(ty);
}
что я делаю не так?