示例#1
0
    // Damages the player on collision
    void OnTriggerEnter(Collider other)
    {
        PlayerChampion playerChampion = other.GetComponent <PlayerChampion>();

        if (playerChampion != null)
        {
            PhotonView photonView = playerChampion.GetComponent <PhotonView>();
            if (photonView.isMine)
            {
                photonView.RPC("Damage", PhotonTargets.All, damage, null);
            }
        }
    }
示例#2
0
    void EntityDamage(float amount, int attackerId)
    {
        // Update the health bar UI and kill the entity if necessary
        if (useEntityBehaviour)
        {
            health = Mathf.Max(health - amount, 0f);
            if (healthBarFill != null)
            {
                healthBarFill.fillAmount = health / maxHealth;
            }
            if (health <= 0f)
            {
                IsDead = true;

                // Give XP to all enemy champions who are not in the area
                if (PhotonNetwork.isMasterClient)
                {
                    Collider[] hitColliders = Physics.OverlapSphere(transform.position, XPRadius);
                    for (int i = 0; i < hitColliders.Length; i++)
                    {
                        PlayerChampion playerChampion = hitColliders[i].GetComponent <PlayerChampion>();
                        if (playerChampion != null)
                        {
                            if (playerChampion.PhotonView.owner.GetTeam() != team)
                            {
                                ChampionXP championXP = playerChampion.GetComponent <ChampionXP>();
                                championXP.photonView.RPC("GiveXP", PhotonTargets.All, XPOnDeath, false);
                            }
                        }
                    }
                }

                // Tell other scripts we're dead
                if (onEntityDeath != null)
                {
                    onEntityDeath(attackerId);
                }

                // Destroy the bullet
                if (PhotonNetwork.isMasterClient)
                {
                    PhotonNetwork.Destroy(gameObject);
                }
            }
        }
    }
示例#3
0
    // Called when the bullet collides with an object
    void OnCollide(GameObject collision)
    {
        PlayerChampion playerChampion = collision.GetComponent <PlayerChampion>();
        Entity         entity         = collision.GetComponent <Entity>();
        Turret         turret         = collision.GetComponent <Turret>();
        Inhibitor      inhibitor      = collision.GetComponent <Inhibitor>();
        Nexus          nexus          = collision.GetComponent <Nexus>();

        // Collision with player champion
        if (playerChampion != null)
        {
            PhotonView photonView = playerChampion.GetComponent <PhotonView>();
            if (PhotonNetwork.isMasterClient && photonView.owner.GetTeam() != team)
            {
                photonView.RPC("Damage", PhotonTargets.All, damage, shooterId);
            }
        }

        // Collision with turret
        else if (turret != null)
        {
            PhotonView photonView = turret.GetComponent <PhotonView>();
            Targetable targetable = turret.GetComponent <Targetable>();
            if (PhotonNetwork.isMasterClient && targetable.allowTargetingBy == team)
            {
                photonView.RPC("Damage", PhotonTargets.All, damage, shooterId);
            }
        }

        // Collision with inhibitor
        else if (inhibitor != null)
        {
            PhotonView photonView = inhibitor.GetComponent <PhotonView>();
            Targetable targetable = inhibitor.GetComponent <Targetable>();
            if (PhotonNetwork.isMasterClient && targetable.allowTargetingBy == team)
            {
                photonView.RPC("Damage", PhotonTargets.All, damage, shooterId);
            }
        }

        // Collision with nexus
        else if (nexus != null)
        {
            PhotonView photonView = nexus.GetComponent <PhotonView>();
            Targetable targetable = nexus.GetComponent <Targetable>();
            if (PhotonNetwork.isMasterClient && targetable.allowTargetingBy == team)
            {
                photonView.RPC("Damage", PhotonTargets.All, damage, shooterId);
            }
        }

        // Collision with entity (ie. minion)
        else if (entity != null)
        {
            PhotonView photonView = entity.GetComponent <PhotonView>();
            if (PhotonNetwork.isMasterClient && entity.team != team)
            {
                photonView.RPC("EntityDamage", PhotonTargets.All, damage, shooterId);
            }
        }

        // Destroy the bullet regardless of the above
        Destroy(gameObject);
    }