Esempio n. 1
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);
    }