本文整理汇总了C#中UnityEngine.Collision2D类的典型用法代码示例。如果您正苦于以下问题:C# Collision2D类的具体用法?C# Collision2D怎么用?C# Collision2D使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Collision2D类属于UnityEngine命名空间,在下文中一共展示了Collision2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnCollisionEnter2D
// 공과의 충돌
void OnCollisionEnter2D(Collision2D coll)
{
foreach(ContactPoint2D contact in coll.contacts) {
if(contact.collider.gameObject.tag == "Ball") {
float speed = contact.collider.gameObject.GetComponent<Ball>().currentSpeed;
float barWidth = this.GetComponent<Renderer>().bounds.size.x;
float percentage = (contact.point.x - transform.position.x) / barWidth / 2;
// 부착 모드인가?
/*if(state == State.Attached) {
AttachedInfo info = new AttachedInfo();
info.velocity = contact.collider.GetComponent<Rigidbody2D>().velocity;
contact.collider.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
// 딱 닿았을 때의 좌표값과 퍼센트치를 저장해줌
info.ball = contact.collider.gameObject;
info.ballPosition = contact.collider.transform.position;
info.barPosition = tf.position;
info.percentage = percentage;
attachedBalls.Add(info);
} else {*/
contact.collider.GetComponent<Rigidbody2D>().AddForce(new Vector2(percentage * 5 * (speed * 50), 0));
if(contact.collider.GetComponent<Rigidbody2D>().velocity.y < 0)
contact.collider.GetComponent<Rigidbody2D>().velocity *= -1;
//}
break;
}
}
}
示例2: OnCollisionEnter2D
void OnCollisionEnter2D(Collision2D coll)
{
if (!Data.Paused)
{
hit=true;
}
}
示例3: CreateRicochet
void CreateRicochet(GameObject currentRickochet, Collision2D col, bool isRicochet)
{
foreach (ContactPoint2D contact in col.contacts) {
Debug.DrawRay (contact.point, contact.normal, Color.white);
Quaternion rotation = Quaternion.LookRotation (contact.normal);
rotation [0] = 0;
rotation [1] = 0;
GameObject projectile = Instantiate (currentRickochet, contact.point, rotation) as GameObject;
//projectile.transform.eulerAngles = new Vector3(0, 0, projectile.transform.eulerAngles.z);
Vector3 v = projectile.transform.rotation.eulerAngles;
projectile.transform.rotation = rotation;
//Debug.Log("Contact normal: " + contact.normal + " Contact position: " + contact.point + " Rotation: " + rotation);
if (isRicochet && ricochetSounds.Length != 0) {
AudioSource ricochetAudioSource = projectile.AddComponent<AudioSource> ();
ricochetAudioSource.clip = ricochetSounds [Random.Range (0, ricochetSounds.Length)];
ricochetAudioSource.volume = 0.12f;
ricochetAudioSource.maxDistance = 30;
ricochetAudioSource.Play ();
}
projectile.SetActive (true);
Destroy (projectile, 1f);
}
}
示例4: OnCollisionEnter2D
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.transform.tag == "Obstacle")
{
IsColliding = true;
}
}
示例5: OnCollisionExit2D
void OnCollisionExit2D(Collision2D coll)
{
if (coll.transform.tag == "Obstacle")
{
IsColliding = false;
}
}
示例6: OnCollisionEnter2D
void OnCollisionEnter2D(Collision2D other)
{
if (DestroyInColisionEvent)
{
CheckCollider(other.gameObject);
}
}
示例7: OnCollisionEnter2D
private void OnCollisionEnter2D( Collision2D c )
{
// When a collision is detected, we reflect the velocity of the ball, making it bounce off whatever it hit
// (This might already be handled by Unity, I'm not sure. It seems to work better with this code.)
rigidbody2D.velocity = Vector3.Reflect( c.relativeVelocity, c.contacts[0].normal );
switch( c.gameObject.tag ) {
case "paddle": // If we hit a paddle...
if( c.gameObject.audio != null ) // ...and the paddle has a sound...
{
c.gameObject.audio.volume = PlayerPrefs.GetInt( "Volume", 50 ) / 100.0f;
c.gameObject.audio.Play(); // ...play that sound.
}
if( this.speed < this.maxSpeed ) // If the current speed is less than the maximum speed...
this.speed += this.speedIncrement; // ...increase the speed of the ball.
// Run awesome screen shake effect. :D
Vector2 shakeMagnitude = c.relativeVelocity.normalized * this.screenShakeEffect;
StartCoroutine( Shaker.Shake( Camera.main.transform, .25f, shakeMagnitude ) );
break;
case "bounds":
// Play a random bound sound if we collide with the roof/floor bounds.
int sndIdx = Random.Range( 0, this.boundSounds.Length );
audio.clip = this.boundSounds[sndIdx];
audio.volume = PlayerPrefs.GetInt( "Volume", 50 ) / 100.0f;
audio.Play();
break;
}
// Make sure the speed doesn't exceed the maximum
if( this.speed > this.maxSpeed )
this.speed = this.maxSpeed;
}
示例8: OnCollisionEnter2D
private void OnCollisionEnter2D(Collision2D other)
{
if (other.collider.tag == Tags.player)
{
other.gameObject.GetComponent<Player>().Die();
}
}
示例9: OnCollisionExit2D
public override void OnCollisionExit2D(Collision2D collision)
{
if (string.IsNullOrEmpty(tag.Value) || tag.Value.Equals(collision.gameObject.tag)) {
collidedGameObject.Value = collision.gameObject;
exitedCollision = true;
}
}
示例10: OnCollisionStay2D
private void OnCollisionStay2D(Collision2D collision)
{
if (CollisionStay2D != null)
{
CollisionStay2D(this, collision);
}
}
示例11: OnCollisionEnter2D
void OnCollisionEnter2D(Collision2D col)
{
if (infiniteJumps) return;
numJumps--;
if(numJumps == 0) StartCoroutine(Fall());
}
示例12: OnCollisionStay2D
void OnCollisionStay2D(Collision2D col)
{
if (col.gameObject.tag == "Player")
{
col.gameObject.GetComponent<CharHealth>().Damage(Attack);
}
}
示例13: OnCollisionEnter2D
public void OnCollisionEnter2D(Collision2D collision)
{
if (MainScript.SelfType == MainScript.PlayerType.Client)
{
MainScript.SelfPlayer.Role.HandleCollision(this, collision);
}
}
示例14: OnCollisionEnter2D
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "Player" || coll.gameObject.tag == "PlayerAttack")
dead = true;
if (coll.gameObject.tag == "Enemy" || coll.gameObject.tag == "Health" || coll.gameObject.tag == "Untagged")
Physics2D.IgnoreCollision(this.gameObject.collider2D, coll.gameObject.collider2D);
}
示例15: OnCollisionEnter2D
// not supported
#else
// ReSharper disable once UnusedMember.Local
private void OnCollisionEnter2D(Collision2D coll) {
if (!_isValid) {
return;
}
KillableToAlert.CollisionEnter2D(coll);
}