コード例 #1
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.tag == "minion")
     {
         Debug.Log("Hit");
         MinionHealthManager enemyScript = collision.gameObject.GetComponent <MinionHealthManager>();
         enemyScript.TakeDamage(damage);
     }
     Debug.Log(collision.gameObject.name);
     Destroy(this.gameObject);
 }
コード例 #2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        HealthManager       towerH = collision.GetComponent <HealthManager>();
        HealtManagerNexus   nexus  = collision.GetComponent <HealtManagerNexus>();
        MinionHealthManager minion = collision.GetComponent <MinionHealthManager>();
        PlayerHealthManager player = collision.GetComponent <PlayerHealthManager>();



        int idTeam2TowerLayer;
        int idTeam2Nexus;
        int idTeam2Minion;
        int idTeamPlayer;

        if (this.gameObject.layer == 15)
        {
            idTeam2TowerLayer = LayerMask.NameToLayer("Team2-Tower");
            idTeam2Nexus      = LayerMask.NameToLayer("Team2-Tower");
            idTeam2Minion     = LayerMask.NameToLayer("Team2-Minion");
            idTeamPlayer      = LayerMask.NameToLayer("Team2-Player");
        }
        else
        {
            idTeam2TowerLayer = LayerMask.NameToLayer("Team1-Tower");
            idTeam2Nexus      = LayerMask.NameToLayer("Team1-Tower");
            idTeam2Minion     = LayerMask.NameToLayer("Team1-Minion");
            idTeamPlayer      = LayerMask.NameToLayer("Team1-Player");
        }

        if (collision.gameObject.layer == idTeam2TowerLayer && collision.tag != "Nexus")
        {
            if (!collision.isTrigger)
            {
                Destroy(gameObject);
                towerH.TakeDamage(1);
            }
        }
        else if (collision.gameObject.layer == idTeam2Nexus && collision.tag == "Nexus")
        {
            if (!collision.isTrigger)
            {
                Destroy(gameObject);
                nexus.TakeDamage(1);
            }
        }
        else if (collision.gameObject.layer == idTeam2Minion && collision.tag == "minion")
        {
            if (!collision.isTrigger)
            {
                Destroy(gameObject);
                minion.TakeDamage(2);
            }
        }
        else if (collision.gameObject.layer == idTeamPlayer && collision.tag == "Player")
        {
            if (!collision.isTrigger)
            {
                Destroy(gameObject);
                player.TakeDamage(2);
            }
        }
    }