当前位置: 首页>>代码示例>>C#>>正文


C# Collider2D.GetComponents方法代码示例

本文整理汇总了C#中UnityEngine.Collider2D.GetComponents方法的典型用法代码示例。如果您正苦于以下问题:C# Collider2D.GetComponents方法的具体用法?C# Collider2D.GetComponents怎么用?C# Collider2D.GetComponents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Collider2D的用法示例。


在下文中一共展示了Collider2D.GetComponents方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ActionCheck

        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();
              }
            }
              }
        }
开发者ID:musicm122,项目名称:The-Depths-of-H-E-double-hockey-stick,代码行数:34,代码来源:MeleeAttackAction.cs

示例2: OnTriggerEnter2D

    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();
        }
    }
开发者ID:Kazetsukai,项目名称:UnityGames,代码行数:16,代码来源:PlayerControl.cs

示例3: OnTriggerEnter2D

        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);
            }
        }
开发者ID:hosfordryan,项目名称:Rougelike,代码行数:53,代码来源:Player.cs


注:本文中的UnityEngine.Collider2D.GetComponents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。