• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# UnityEngine.Collider2D类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Collider2D类属于UnityEngine命名空间,在下文中一共展示了Collider2D类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: OnTriggerEnter2D

 void OnTriggerEnter2D(Collider2D c)
 {
     //print ("Pokeball pushes back "+c.gameObject.name);
     if (c.gameObject.GetComponent<ReceiveKnockback>()!=null && c.gameObject.name != my_parent_name && !c.GetComponent<PlayerController>().locked) {
         c.gameObject.GetComponent<Consciousness>().TakeDamage(3, pid);
         //if what we hit is a player and isn't the player who made us...
         Vector2 knockback = GetComponent<Rigidbody2D>().velocity;
         knockback.Normalize ();
         knockback.x *= KNOCKBACK_AMOUNT;
         knockback.y *= KNOCKBACK_AMOUNT;
         Knockback knockbackObject = new Knockback(KNOCKBACK_TIME,knockback);
         c.gameObject.SendMessage("GetKnockedBack", knockbackObject);
         //...activate the GetKnockedBack function of the thing we just hit
         //causing them to fly backward! In players, this function is in PlayerMovement.
     }
     //ADD EXCEPTIONS FOR DIE_ON_CONTACT object destroys here \/
     if (die_on_contact && c.gameObject.name != my_parent_name && c.gameObject.name!="Ring"
         && c.tag != "Coin" && c.tag != "Item" && c.tag != "Melee Hitbox" && c.tag != "Portal"
         && c.tag != "Death Floor"){
         //if we hit ANYTHING but the player we came from
         GameObject expl_temp = (GameObject) Instantiate(explosion, transform.position, Quaternion.identity);
         Destroy(expl_temp, expl_temp.GetComponent<ParticleSystem>().startLifetime);
         Destroy (gameObject);
     }
 }
开发者ID:mwdewey,项目名称:GameDev2,代码行数:25,代码来源:CauseKnockback.cs


示例2: OnTriggerEnter2D

 void OnTriggerEnter2D(Collider2D other)
 {
     if(other.gameObject.tag == "Coin")
     {
         isActive = !isActive;
     }
 }
开发者ID:PaulElmo,项目名称:Listen_In-Backup-,代码行数:7,代码来源:ButtonsActivator.cs


示例3: OnTriggerEnter2D

	void OnTriggerEnter2D(Collider2D other)
	{
		if((other.gameObject.tag == ("LeftBullet") || other.gameObject.tag == ("RightBullet")) && gameObject.tag == ("Player1"))
		{
			gameController.playerHPDown();
		}

		if((other.gameObject.tag == ("LeftBullet") || other.gameObject.tag == ("RightBullet")) && gameObject.tag == ("Player2"))
		{
			gameController.playerHPDown();
		}



		if(other.gameObject.tag == ("Coin") && gameObject.tag == ("Player"))
		{
			gameController.playerScoreUp();
		}



		if(other.gameObject.tag == ("Hazzard") && gameObject.tag == ("Player1"))
		{
			gameController.playerHP = 0;
		}


	}
开发者ID:JohnLandi,项目名称:DungeonJam,代码行数:28,代码来源:Player.cs


示例4: OnTriggerEnter2D

 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.gameObject.tag == "spike")
     {
         parent_script.HitSpikes();
     }
 }
开发者ID:HankTheChog,项目名称:Platformers,代码行数:7,代码来源:GroundCheckScript.cs


示例5: OnTriggerEnter2D

 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.name == "Player")
     {
         levelManager.RespawnPlayer();
     }
 }
开发者ID:Weakling,项目名称:CNIT-255-Final-Group-Project,代码行数:7,代码来源:KillPlayer.cs


示例6: OnTriggerEnter2D

 void OnTriggerEnter2D(Collider2D coll)
 {
     if(GameObject.Find("Player") == coll.gameObject)
     {
         GameObject.Find("GameManager").GetComponent<gameManager>().resetGame();
     }
 }
开发者ID:GREEDYHD,项目名称:GGJ16,代码行数:7,代码来源:killPlayer.cs


示例7: OnTriggerEnter2D

	void OnTriggerEnter2D (Collider2D col){

		Debug.Log (gameObject.name + " has collided with " + col.gameObject.name);
		anim.SetBool (bump, true);


	}
开发者ID:TeamLuckySevens,项目名称:MarioRecon,代码行数:7,代码来源:Bump.cs


示例8: OnTriggerExit2D

 public void OnTriggerExit2D(Collider2D other)
 {
     //Returning to patrol state after Player exits within time frame
     if (other.CompareTag("Player")){
         ToPatrolState();
     }
 }
开发者ID:ChristopherElten,项目名称:octgamejam,代码行数:7,代码来源:AlertState.cs


示例9: OnTriggerEnter2D

 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.gameObject.tag == "Player")
     {
         col.gameObject.SendMessage("getHit");
     }
 }
开发者ID:Neesd,项目名称:KirbysAdventure,代码行数:7,代码来源:PowerBeamEnemy.cs


示例10: OnTriggerEnter2D

 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.CompareTag ("NormalArrow") || other.CompareTag ("SplittedArrow")) {
         nnflag = true;
         transform.FindChild("Heart").gameObject.SetActive(true);
     }
 }
开发者ID:Armour,项目名称:LoveArrow,代码行数:7,代码来源:NnControl.cs


示例11: OnTriggerEnter2D

	void OnTriggerEnter2D(Collider2D other){
		if(other.transform.parent){
			Destroy(other.transform.parent.gameObject);
		}else{
			Destroy(other.gameObject);
		}
	}
开发者ID:yun63,项目名称:unity_projects,代码行数:7,代码来源:LeftDestroy.cs


示例12: OnTriggerEnter2D

 void OnTriggerEnter2D(Collider2D collider)
 {
     if (collider.gameObject.tag == "Player") {
         this.playerScript.OnItemCollected(this.itemName);
         Destroy(this.gameObject);
     }
 }
开发者ID:pedronalbert,项目名称:maduro-bros-unity,代码行数:7,代码来源:ItemMarioDetection.cs


示例13: OnTriggerEnter2D

 void OnTriggerEnter2D(Collider2D enemy)
 {
     if (enemy.gameObject.GetComponent<Player> () == null)
         return;
     Debug.Log ("trigger entered");
     eventHandler.HandleClash ();
 }
开发者ID:insanity-corp,项目名称:workingtitle,代码行数:7,代码来源:Player.cs


示例14: OnTriggerEnter2D

    void OnTriggerEnter2D(Collider2D c)
    {
        //レイヤー名取得
        string layerName = LayerMask.LayerToName(c.gameObject.layer);

        //レイヤー名がBullet(Player)以外のとき
        if( layerName != "Bullet(Player)") return;

        //PlayerBulletのTransformを取得
        Transform playerBulletTransform = c.transform.parent;

        //Bulletコンポーネントを取得
        Bullet bullet = playerBulletTransform.GetComponent<Bullet> ();

        //ヒットポイントを減らす
        hp = hp - bullet.power;

        //弾の削除
        Destroy(c.gameObject);

        //ヒットポイントが0以下であれば
        if (hp <= 0) {

            //スコアコンポーネントを取得してポイントを追加
            FindObjectOfType<Score>().AddPoint(point);

            //爆発
            spaceship.Explosion ();

            //エネミーの削除
            Destroy (gameObject);
        } else {
            spaceship.GetAnimator ().SetTrigger ("Damage");
        }
    }
开发者ID:Ellurein,项目名称:Tutorial,代码行数:35,代码来源:Enemy.cs


示例15: OnTriggerEnter2D

 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.tag == "Fog") {
         col.gameObject.GetComponent<FogMovement>().multiplier *= -1;
         StartCoroutine(DeadTime(col.gameObject));
     }
 }
开发者ID:CharAlis,项目名称:AsylumJam,代码行数:7,代码来源:ChangeFogDirection.cs


示例16: AssignReferences

    void AssignReferences()
    {
        myCollider = GetComponent<Collider2D>();
        myCollider.isTrigger = true;

        animator = GetComponent<Animator>();
    }
开发者ID:imann24,项目名称:Beauty,代码行数:7,代码来源:PlayAnimationOnCollide.cs


示例17: OnTriggerEnter2D

 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.gameObject.tag == "Player")
     {
         col.gameObject.GetComponent<Damageable>().OnTakeDamage(m_attack.GetDamage(gameObject.transform));
     }
 }
开发者ID:Silcoish,项目名称:AgeOfAnubis,代码行数:7,代码来源:PROJ_Laser.cs


示例18: OnTriggerEnter2D

 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.tag == "Default")
     {
         Destroy(gameObject);
     }
 }
开发者ID:Vinyl7th,项目名称:RedneckRetribution,代码行数:7,代码来源:AssaltBullet.cs


示例19: OnTriggerEnter2D

 public void OnTriggerEnter2D(Collider2D other)
 {
     if(other.GetComponent<EnemyIdentifier>())
     {
         Destroy(_identifier.Handler.gameObject);
     }
 }
开发者ID:sathiyavrs,项目名称:MMM-Fingers-Xtreme,代码行数:7,代码来源:CoinEnemyHander.cs


示例20: OnTriggerStay2D

 void OnTriggerStay2D(Collider2D other)
 {
     if (Input.GetKey (KeyCode.DownArrow)){
         simon.next_level2 ();
         endtime = Time.time + .8f;
     }
 }
开发者ID:Qmando,项目名称:EECS494-Castlevania,代码行数:7,代码来源:level_switch2.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UnityEngine.Collision类代码示例发布时间:2022-05-26
下一篇:
C# UnityEngine.Collider类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap