# Unet how to control child gameobject?

I'm currently getting into the Unity networking system called unet. I have a child of the local player authority, the weapon. The weapon (PlasmaCannon_left and right) have a script handling firing, because weapons can be replaced, and have different firing intervals, this seemed to me to be the easier way. However, they won't fire.

Hierarchy:

(simplified) Weapon Code:

public void Start() {
Debug.Log("Weapon Spawned.");
if (isLocalPlayer) {
Debug.Log("Weapon set as local player");
}
}

public void Update() {
if (isLocalPlayer) {
if (firingTimer <= firingInterval){
firingTimer += Time.deltaTime;
}
if (firingTimer >= firingInterval) {
if (Input.GetButton("Fire1") && firingMode == FiringMode.Primary) {
CmdFire();
}
if (Input.GetButton("Fire2") && firingMode == FiringMode.Secondary) {
CmdFire();
}
}
}
}

[Command]
public void CmdFire() {
Debug.Log("Firing Bullet.");
}


I am getting the "Weapon Spawned." log message, but nothing inside isLocalPlayer conditions is happening even though I have added a networkidentity component and set Local Player Authority to true.

Like I said, I'm still learning so I have no clue what's going wrong here.

• You do not have the "Weapon set as local player" log message right? Then the isLocalPlayer variable must be at false. Can you put a breakpoint to check? – realUser404 Dec 2 '16 at 17:19
• ^ I agree, try printing out isLocalPlayer before that if instead of just saying "Weapon Spawned." and see if it gives false (it probably does) and find out why it does. We don't have the rest of your code so we don't know what the class of isLocalPlayer is let alone why it doesn't work. (is it even a boolean or an int or something you can check for true vs false? is it ever being set or just initialized?) Does this object even have access to that variable? – John Hamilton Dec 2 '16 at 17:47
• yes, it is false, what i cant figure out is why it is false. it's a child of the player gameobject. – Kevin Kuyl Dec 2 '16 at 19:49
• @KevinKuyl, actually, they do. – Gnemlock Dec 4 '16 at 23:32
• @realUser404 i figured out the problem may be a lot deeper than i initially thought. the player gameobject doesn't even get spawned properly. seems i still have a lot to learn about unet. – Kevin Kuyl Dec 8 '16 at 3:26

for some reason isLocalPlayer is not inherited from its parent, the gameobject also did not have client authority, i solved it by calling a function in the PlayerController to actually fire the bullet, only using variables used in the weapon/bullet objects.

if (isLocalPlayer) {
Debug.Log("Weapon set as local player");
}


This wont work if it is a child of the gameobject with local authority (the network manager recognizes the parent gameobject as the local player).

Instead, try checking "if" the gameobject is a child of the gameobject recognized as the local player. Using your example...

    if (!gameObject.transform.parent.gameObject.GetComponent<NetworkIdentity>().isLocalPlayer)
{
Debug.Log("Weapon set as local player");
}


Now see if the debug message is displayed. Note: For anyone else coming across the net, just replace the debug message with "return;" as you would normally using that function.