public void FireLaserGun() { GameObject[] objArr = GameObject.FindGameObjectsWithTag("NetworkPlayer"); for (int i = 0; i < objArr.Length; i++) { NetworkPlayerController controller = objArr[i].GetComponent <NetworkPlayerController>(); if (controller) { controller.FireLaserGun(); energyManager.GetComponent <EnergyManager>() .decreaseEnergy(energyManager.GetComponent <EnergyManager>() .primaryLaserCost); } } }