本文整理汇总了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();
}
}
}
}
示例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();
}
}
示例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);
}
}