Hi,
I’ve been trying to do some multiplayer stuff in unity, but am having a hard time understanding some things. My problem right now is the following: I instantiate a player object in the OnConnectedToServer() function of a script, and this works fine. I’ve got a couple of scripts running on the player object, and these only run on the players game, as intended, using:
function Awake()
{
if(!networkView.isMine)
{
this.enabled = false;
}
}
however, I use one of these scripts to let the player fire bullets, and these bullets have some scripts of their own using the same isMine thing.
I suspected this would work, since I am just instantiating an object on one of my own objects, but for some reason the bullets fired don’t seem to be owned by the player.
I found this by looking at the player object and the fired bullets in the inspector while testing. All scripts with the above code were active on the player object, but similar scripts on the bullets fired were not.
Is this normal? Am I just missing something here? For refference, here is some of my code:
//This is called on the login script, Don't mind the array, as for now i is always 0;
function OnConnectedToServer()
{
Network.Instantiate(playerShip,spawnersT1*.transform.position,transform.rotation,0);*
Network.Instantiate(playerCam,spawnersT1_.transform.position-transform.forward10,transform.rotation,0);_
_}*_
//This is a part of a script running on my player ship. It calls an RPC to spawn a bullet when requirements are met.
function Awake()
{
* if(!networkView.isMine)*
* {*
* this.enabled=false;*
}
}
function Update()
{
* OverheatTimer();*
* if(Input.GetMouseButton(0) && Time.time > nextFire && !overHeated)*
* {*
* nextFire = Time.time + fireRate;*
* networkView.RPC(“SpawnBullet”,RPCMode.All, gunNode.position, gunNode.rotation);*
* }*
}
@RPC
function SpawnBullet(pos: Vector3, rot: Quaternion)
{
* var bullet: GameObject = Instantiate(gunType, pos, rot);*
}
this spawns bullets just as I needed, but for some reason the bullets aren’t owned by the player, even tho the script that runs on the ship and fires the bullets, is owned by the player.
Thanks! Very useful answer, never knew the server owned all objects by default. Now it all makes sense!
– SomeRandomGuy