public override void ActionCheck(Collider2D c)
        {
            base.ActionCheck(c);
              if (IsPreformingAction && AttackEffectTags.Contains(c.gameObject.tag) && AttactkCollider2D.enabled)
              {
            if (c.gameObject.tag == "Enemy")
            {
              //var enemies = c.GetComponentsInParent<Damagable>();
              var enemies = c.GetComponents<Damagable>();
              for (var i = 0; i < enemies.Count(); i++)
              {
            enemies[i].TakeDamage("Player", DamageAmt);
            //todo: figure out the angle of approach and bounce enemy\player off when damaged
            //c.GetComponentsInParent( )
            ////c.OverlapPoint()
            //enemies[i].transform.Move();
              }
            }

            if (c.gameObject.tag == "Player")
            {
              var player = c.GetComponentsInParent<Damagable>();
              for (var i = 0; i < player.Count(); i++)
              {
            player[i].TakeDamage("Enemy", DamageAmt);
            //todo: figure out the angle of approach and bounce enemy\player off when damaged

            //c.GetComponentsInParent( )
            ////c.OverlapPoint()
            //enemies[i].transform.Move();
              }
            }
              }
        }
コード例 #2
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        if (collider.GetComponents<MonoBehaviour>().Any(c => c is ICollidableEnemy))
        {
            var explosion = (GameObject)Instantiate(ExplosionEffect);
            explosion.transform.position = transform.position;
            explosion.rigidbody2D.AddForce(rigidbody2D.velocity * 10);
            Destroy(gameObject);
        }

        var collectables = collider.GetComponents<MonoBehaviour>().OfType<ICollectable>();
        foreach (var collectable in collectables)
        {
            collectable.Collect();
        }
    }
コード例 #3
0
ファイル: Player.cs プロジェクト: hosfordryan/Rougelike
        void OnTriggerEnter2D(Collider2D coll)
        {
            Debug.Log("Colliding with: "+coll.gameObject.name);
            if(coll.gameObject.name=="Enemy1(Clone)"){
                BoxCollider2D enColl = null;
                BoxCollider2D[] enColls = coll.GetComponents<BoxCollider2D>();
                foreach(BoxCollider2D encoll in enColls){
                    if(!encoll.isTrigger){
                        enColl = encoll;
                    }
                }
                if(!waitActive){
                    Physics2D.IgnoreLayerCollision(9,8,true);
                    enColl.enabled=false;
                    //Debug.Log("Invincible");
                    StartCoroutine(HitInvincible(hitStun,enColl));		//CHANGED from coll to enColl
                    if(!hitting){
                        hit(1f);
                    }
                }
            }

            if(coll.gameObject.name=="floater(Clone)"){
                    Debug.Log("!!!!! HIT BY FLOATER");
                    CircleCollider2D enColl = null;
                    CircleCollider2D[] enColls = coll.GetComponents<CircleCollider2D>();
                    foreach(CircleCollider2D encoll in enColls){
                        if(!encoll.isTrigger){
                            enColl = encoll;
                        }
                    }
                    if(!waitActive){
                        Physics2D.IgnoreLayerCollision(9,8,true);
                        enColl.enabled=false;
                        //Debug.Log("Invincible");
                        StartCoroutine(HitInvincible(hitStun,enColl));		//CHANGED from coll to enColl
                        if(!hitting){
                            hit(1f);
                        }
                    }

            }
            if (coll.gameObject.tag == "Exit") {
                resetLevel ();
            }
            if(coll.gameObject.name=="SpeedBoots"){
                Debug.Log("COLLIDING with SpeedBootss");
                float dur = GameObject.Find(coll.gameObject.name).GetComponent<SpeedBoots>().duration;
                float amt = GameObject.Find(coll.gameObject.name).GetComponent<SpeedBoots>().speedBoost;
                StartCoroutine(speedBoost(dur,amt));
                GameObject.Destroy(coll.gameObject);
            }
        }