So I want to spawn an explosion from a missile that the player shoots.
If I try to add the “explosion” like this:
(it is actually for a mine but it is actually the same)
void OnCollisionEnter(Collision coll)
{
Debug.Log("playercollision");
if (coll.gameObject.tag == "Player")
{
CmdOnCollision();
NetworkServer.Destroy(gameObject);
col = true;
}
}
[Command]
void CmdOnCollision()
{
expo = (GameObject)Instantiate(
exp,
minecoll.transform.position,
minecoll.transform.rotation);
NetworkServer.Spawn(expo);
}
it give me the following error
“Trying to send command for object without authority.”
I actually have a workaround, where I check the collision of the missile with a static variable and then add the explosion prefab over the shooting script.
But there are 2 problems,
1st I can only instantiate one missile at once. If I instantiate more then one missile I only can destroy the last missile because the script loses the properties of the others.
2nd I want to have the bullets/missiles/mine etc. instantiate their explosions themselves and destroy themselves too.
How can I achieve giving my objects player authority?