Example #1
0
    /// <summary>
    /// Damage the sail when hit by a cannonball.
    /// </summary>

    void OnTriggerEnter(Collider col)
    {
        Cannonball cb = col.GetComponent <Cannonball>();

        if (cb != null && cb.damage > 0f)
        {
            // Damage the sails
            float damage = mStats.ApplyDamageToSails(cb.damage);

            // Print the damage text over the sail
            if (damage > 0f)
            {
                ScrollingCombatText.Print(gameObject, "-" + Mathf.RoundToInt(damage), new Color(1f, .4f, 0f));
            }
        }
    }
Example #2
0
    private void OnCollisionEnter(Collision collision)
    {
        Debug.Log(collision.gameObject.name + ":  hit!!");

        Cannonball cb = collision.gameObject.GetComponent <Cannonball>();

        if (cb != null && cb.damage > 0f && photonView.isMine)
        {
            float damage = mStats.ApplyDamageToSails(cb.damage);
            ///////photonView.RPC("ApplyDamageToSails", RpcTarget.All, cb.damage);
            Debug.Log("Damage: " + damage);


            if (photonView.isMine)
            {
                GameObject newBoomEffect = PhotonNetwork.Instantiate("Boom", transform.position, Quaternion.identity, 0);
                //destroy it
            }

            //TextUPdate
            BattleManger.Instance.PlayerHealthText.text    = mStats.ShipHealth.ToString() + "/" + BattleManger.Instance.maxHealthPlayer;
            BattleManger.Instance.PlayerHealthSlider.value = mStats.ShipHealth;


            photonView.RPC("MajVie", PhotonTargets.Others, mStats.ShipHealth, BattleManger.Instance.maxHealthPlayer);

            if (mStats.ShipHealth <= 0)
            {
                BattleManger.Instance.losePanel.SetActive(true);
                BattleManger.Instance.PlayersUI.SetActive(false);


                BattleManger.Instance.winner = BattleManger.Instance.EnemyNameText.text.ToString();
                photonView.RPC("BattleWinnerIs", PhotonTargets.Others);

                photonView.RPC("GameWin", PhotonTargets.Others);
                //BattleManger.Instance.winner = BattleManger.Instance.EnemyNameText.text.ToString();

                ///Debug.LogError("OnCollisionEnter.Winner is " + BattleManger.Instance.winner + " : MasterClient" + PhotonNetwork.isMasterClient);
            }

            // cb.DestroyOnHit();
        }
    }