本文整理汇总了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;
}
}
示例2: OnCollisionEnter2D
void OnCollisionEnter2D(Collision2D coll)
{
Debug.Log ("Collision");
if (coll.gameObject.name == "Player") {
gameController.onExit();
}
}
示例3: OnCollisionEnter2D
void OnCollisionEnter2D(Collision2D other)
{
if(other.transform.tag == "movingPlat")
{
transform.parent = other.transform;
}
}
示例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));
}
}
}
}
}
示例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");
}
}
示例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
}
示例7: OnCollisionEnter2D
void OnCollisionEnter2D(Collision2D col)
{
if( col.gameObject.tag=="Player"){
Destroy(this.gameObject);
MusicControl._instant.PlayAwardSound();
}
}
示例8: OnCollisionEnter2D
void OnCollisionEnter2D(Collision2D other)
{
if (other != null && other.gameObject.tag == "Player") {
//transform.root.GetComponentInChildren<RotationDoor>().InCollider(true);
//print("collide enter");
}
}
示例9: OnCollisionEnter2D
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "Rock" || col.gameObject.tag == "BonusAlien")
{
DestroyProj();
}
}
示例10: OnCollisionEnter2D
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.layer == LayerMask.NameToLayer("Terrain"))
{
Attach();
}
}
示例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";}
}
}
示例12: OnCollisionEnter2D
void OnCollisionEnter2D(Collision2D other)
{
Fish otherFish = other.transform.GetComponent<Fish>();
if (otherFish)
otherFish.Despawn();
}
示例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;
}
}
示例14: OnCollisionExit2D
void OnCollisionExit2D(Collision2D hit)
{
if(hit.gameObject.tag == "Player")
{
isTouching = false;
}
}
示例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");
}