Example #1
0
    public void takeDamage(int amount, Object instigator)
    {
        if (PhotonNetwork.IsConnected && !photonView.IsMine)
        {
            return;
        }

        if (amount <= 0)
        {
            Debug.LogError("Cannot apply less than zero damage to a tower");
            return;
        }

        if (PhotonNetwork.IsConnected)
        {
            photonView.RPC("TakeDamageRPC", RpcTarget.All, amount);
        }
        else
        {
            TakeDamageRPC(amount);
        }

        healthBar.SetHealth(m_health);  //Update Healthbar UI

        if (m_health <= 0)
        {
            AnalyticsHelpers.reportTowerDestroyed(this, instigator ? instigator.name : "Unknown");

            if (CameraEffectsController.instance)
            {
                CameraEffectsController.instance.CameraShake(destroyedShakeIntensity, destroyedShakeDuration, destroyedShakeRotation);
            }

            destroyTower(this);
        }
    }