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.
"Weapon set as local player"
log message right? Then theisLocalPlayer
variable must be at false. Can you put a breakpoint to check? \$\endgroup\$