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


C# Collision2D类代码示例

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


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

示例1: OnCollisionEnter2D

 //collision detection
 void OnCollisionEnter2D(Collision2D hit)
 {
     if(hit.gameObject.tag == "Player")
     {
         isTouching = true;
     }
 }
开发者ID:JCPlusPlus,项目名称:CommunityGame,代码行数:8,代码来源:ClassRoomScripts.cs

示例2: OnCollisionEnter2D

 void OnCollisionEnter2D(Collision2D coll)
 {
     Debug.Log ("Collision");
     if (coll.gameObject.name == "Player") {
         gameController.onExit();
     }
 }
开发者ID:zwarn,项目名称:Squares,代码行数:7,代码来源:ExitScript.cs

示例3: OnCollisionEnter2D

	void OnCollisionEnter2D(Collision2D other)
	{
		if(other.transform.tag == "movingPlat")
		{
			transform.parent = other.transform;
		}
	}
开发者ID:JohnLandi,项目名称:DungeonJam,代码行数:7,代码来源:Player.cs

示例4: OnCollisionExit2D

 void OnCollisionExit2D(Collision2D col)
 {
     if (col.gameObject.tag == "Ground")
     {
         if (stayDown)
         {
             if (col.transform.position.y < transform.position.y)
             {
                 RaycastHit2D hit = Physics2D.Raycast((Vector2)transform.position + colider.offset, Vector2.down, distance);
                 if (hit)
                 {
                     Vector2 normal = -hit.normal;
                     RaycastHit2D hit2 = Physics2D.Raycast((Vector2)transform.position + colider.offset, normal, distance);
                     if (hit2)
                     {
                         Vector2 vec = hit2.point - ((Vector2)transform.position + colider.offset);
                         vec = vec.normalized * (vec.magnitude - colider.radius) * errorPercentage;
                         vec.x = 0;
                         rBody.MovePosition(transform.position + (Vector3)vec);
                     }
                     rBody.velocity = new Vector2(rBody.velocity.x, Mathf.Min(-5f, rBody.velocity.y));
                 }
             }
         }
     }
 }
开发者ID:InfiniteMachine,项目名称:IMSpring2016,代码行数:26,代码来源:StayGrounded.cs

示例5: OnCollisionStay2D

 void OnCollisionStay2D(Collision2D collision)
 {
     if (collision.gameObject.tag == "Barrier" || collision.gameObject.tag == "Tree1" || collision.gameObject.tag == "Tree2" || collision.gameObject.tag == "Tree3" || collision.gameObject.tag == "Apple" || collision.gameObject.tag == "Player" || collision.gameObject.tag == "NPC")
     {
         gameObject.SendMessage("SelectAnotherPath");
     }
 }
开发者ID:EagleEye247,项目名称:Creatures-Collide-V3,代码行数:7,代码来源:Somethingelse.cs

示例6: OnCollisionEnter2D

    public virtual void OnCollisionEnter2D(Collision2D collision)
    {
        if(collision.gameObject.GetComponent<SH_Projectile>()== null)
            return;

        collision.gameObject.GetComponent<SpriteRenderer>().enabled = false; // set so buildings block fireing lanes
    }
开发者ID:the5thvoice,项目名称:SettlingHell-AssignementComplete-,代码行数:7,代码来源:SH_Building.cs

示例7: OnCollisionEnter2D

 void OnCollisionEnter2D(Collision2D col)
 {
     if( col.gameObject.tag=="Player"){
         Destroy(this.gameObject);
         MusicControl._instant.PlayAwardSound();
     }
 }
开发者ID:SangLiang,项目名称:CurryGame,代码行数:7,代码来源:Shield_Controller.cs

示例8: OnCollisionEnter2D

 void OnCollisionEnter2D(Collision2D other)
 {
     if (other != null && other.gameObject.tag == "Player") {
         //transform.root.GetComponentInChildren<RotationDoor>().InCollider(true);
         //print("collide enter");
     }
 }
开发者ID:gpljr,项目名称:HexMaze,代码行数:7,代码来源:DoorCollider.cs

示例9: OnCollisionEnter2D

 void OnCollisionEnter2D(Collision2D col)
 {
     if (col.gameObject.tag == "Rock" || col.gameObject.tag == "BonusAlien")
     {
         DestroyProj();
     }
 }
开发者ID:testedgamer,项目名称:Game-Clones,代码行数:7,代码来源:ProjDestroyer.cs

示例10: OnCollisionEnter2D

 void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.layer == LayerMask.NameToLayer("Terrain"))
     {
         Attach();
     }
 }
开发者ID:DeeCeptor,项目名称:PerilousClimb,代码行数:7,代码来源:AttachToTerrain.cs

示例11: OnCollisionEnter2D

	void OnCollisionEnter2D(Collision2D collide){

		if (collide.gameObject.CompareTag ("leftwall") || collide.gameObject.CompareTag ("rightwall")) {
			clickAudio.Play ();
		}
		if (collide.gameObject.CompareTag ("heart")) {
			kissAudio.Play ();
			Destroy(collide.gameObject);
			Debug.Log("It's a heart!");
			score += 1;
			scoreText.text = "Hearts Stolen : "+ score;	
		}

		if (collide.gameObject.CompareTag ("goal") || collide.gameObject.CompareTag ("land")) {
			weeAudio.Play ();
			deathanim.Play ();
			death = true;
			Debug.Log("I'm happy to die for my master");
			if (collide.gameObject.CompareTag ("goal")) {
				goalText.text = "Yay!\n You finished the ritual\nsuccessfully with "+ score + " hearts";}
			if (collide.gameObject.CompareTag ("land")) {
				goalText.text = "Buu!\n You finished the ritual\nunsuccessfully with "+ score + " hearts";}

		}
	}
开发者ID:snni,项目名称:ggj16,代码行数:25,代码来源:movement.cs

示例12: OnCollisionEnter2D

 void OnCollisionEnter2D(Collision2D other)
 {
     Fish otherFish = other.transform.GetComponent<Fish>();
     if (otherFish)
         otherFish.Despawn();
     
 }
开发者ID:bslupik,项目名称:globalgamejam16,代码行数:7,代码来源:FishBoat.cs

示例13: OnCollisionExit2D

 // when enemy moves it checks when the colliders are not touching anymore CollisionExit
 void OnCollisionExit2D(Collision2D otherCollider)
 {
     if (otherCollider.gameObject.CompareTag ("Ground")) {
         this._isGrounded = true;
         this._isFrontGround = true;
     }
 }
开发者ID:Strifez,项目名称:Cave-Adventure-2D,代码行数:8,代码来源:Enemy_Controller.cs

示例14: OnCollisionExit2D

 void OnCollisionExit2D(Collision2D hit)
 {
     if(hit.gameObject.tag == "Player")
     {
         isTouching = false;
     }
 }
开发者ID:JCPlusPlus,项目名称:CommunityGame,代码行数:7,代码来源:ClassRoomScripts.cs

示例15: OnCollisionEnter2D

	//Catch Collisions 
	void OnCollisionEnter2D(Collision2D collision)
	{

		//Set forces to zero
		bullBody.velocity = Vector3.zero;
		bullBody.angularVelocity = 0;

		//Set the trigger for the bullet to pop
		actionCamera.impactPause();
		animator.SetTrigger ("Collide");

		//Check if it is an enemy
		if (collision.gameObject.tag == "Enemy") {

			//Shake for damage
			actionCamera.startShake ();

			//Get the enemy object
			Enemy e = (Enemy)collision.gameObject.GetComponent ("Enemy");

			//Find our damage, and set it
			int damage = strength * (speed / 20);
			int newHealth = e.getHealth() - damage;

			e.setHealth (newHealth);
		}

		//Lastly remove all force and delete the bullet
		StartCoroutine("BulletHit");
	}
开发者ID:julianpoy,项目名称:HackPoly2016,代码行数:31,代码来源:Bullets.cs


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