Thanks for the response, here is what i tryied;
I have a spawn object called “Object Spawn” which has a network identity.
Also i have a GameManager which has the “Object Spawner” script with network identity on it.
On my player prefab i have a script called;
SpawnObject;
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class SpawnObject : NetworkBehaviour {
void Update () {
if (!isLocalPlayer) return;
if (Input.GetKeyDown(KeyCode.Alpha5))
GameObject.Find(“GameManager”).GetComponent().SpawnCube();
}
}
ObjectSpawner;
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class ObjectSpawner : NetworkBehaviour
{
[SerializeField]
GameObject cubePrefab;
[SerializeField]
GameObject ojectSpawn;
public void SpawnCube()
{
CmdSpawnCube();
}
[Command]
void CmdSpawnCube()
{
GameObject SceneObjects = GameObject.Find(“Object Spawn”);
GameObject Cube = (GameObject)Instantiate(cubePrefab, ojectSpawn.transform.position, Quaternion.identity) as GameObject;
NetworkServer.Spawn(Cube);
Cube.transform.SetParent(SceneObjects.transform);
}
}
To destroy the clicked object;
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class DestroyPickedItem : NetworkBehaviour
{
[SyncVar]
public GameObject Cube;
public Vector2 hotSpot = Vector2.zero;
void OnMouseDown()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 40))
{
CmdDestroyCube();
Cursor.SetCursor(null, Vector2.zero, cursorMode);
}
}
}
[Command]
void CmdDestroyCube()
{
NetworkServer.Destroy(Cube);
}
}
Here is what happens;
Everything works fine by server/host side. But whenever i try to spawn the object on client side it says;
Trying to send command for object without authority.
UnityEngine.Networking.NetworkBehaviour:SendCommandInternal(NetworkWriter, Int32, String)
ObjectSpawner:CallCmdSpawnCube()
ObjectSpawner:SpawnCube() (at Assets/Scripts/ItemInteractionSystem/ObjectSpawner.cs:25)
SpawnObject:Update() (at Assets/Scripts/ItemInteractionSystem/SpawnObject.cs:16)
and also when i delete the object, it destroys only on the client side.
I tried to spawn the object using NetworkServer.SpawnWithClientAuthority which cause some other errors on client side.