- Home /
Question by
cosmologosaurusrex · Apr 20, 2016 at 05:11 PM ·
spawngetcomponentcommand
Player add values to script of spawned unit on spawn in network
Hi! When a player in my game attacks, he spawns boxes that i manage to get spawned in all players games. But what does not work is to give the boxes a damage value from the player attacking, to the boxes when the attack is made. not in multiplayer, it only works in its own game.
Here is the important, simplified part of the code:
void Update () {
if (!isLocalPlayer) {
return;
}
if(attack1){
CmdAttack1();
}
}
[Command]
void CmdAttack1()
{
boxes.Add ((GameObject)Instantiate (hitbox1, transform.position, transform.rotation));
boxes.Add ((GameObject)Instantiate (hitbox1, position2, transform.rotation));
boxcount = boxes.Count;
for(int i=0;i<boxcount;i++){
boxes[i] .GetComponent<hitboxvalues> ().damage = 10;
NetworkServer.Spawn(boxes[i]);
}
Comment
Your answer
