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


C# UnityEngine.Collision2D类代码示例

本文整理汇总了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;
         }
     }
 }
开发者ID:Cube219,项目名称:BlockBuster,代码行数:28,代码来源:Bar.cs

示例2: OnCollisionEnter2D

 void OnCollisionEnter2D(Collision2D coll)
 {
     if (!Data.Paused)
     {
         hit=true;
     }
 }
开发者ID:JonathanHunter,项目名称:ZeroScripts,代码行数:7,代码来源:DadaMissile.cs

示例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);
            }
        }
开发者ID:Kundara,项目名称:project1,代码行数:26,代码来源:Rocket.cs

示例4: OnCollisionEnter2D

 void OnCollisionEnter2D(Collision2D coll)
 {
     if (coll.transform.tag == "Obstacle")
     {
         IsColliding = true;
     }
 }
开发者ID:gracianogodoy,项目名称:GameJam,代码行数:7,代码来源:PeasantControl.cs

示例5: OnCollisionExit2D

 void OnCollisionExit2D(Collision2D coll)
 {
     if (coll.transform.tag == "Obstacle")
     {
         IsColliding = false;
     }
 }
开发者ID:gracianogodoy,项目名称:GameJam,代码行数:7,代码来源:PeasantControl.cs

示例6: OnCollisionEnter2D

 void OnCollisionEnter2D(Collision2D other)
 {
     if (DestroyInColisionEvent)
     {
         CheckCollider(other.gameObject);
     }
 }
开发者ID:urgamedev,项目名称:UnityFighter2D,代码行数:7,代码来源:PermantDestroyPlayerPrefs.cs

示例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;
        }
开发者ID:GDR2014,项目名称:january-SplitPong,代码行数:33,代码来源:BasicBallScript.cs

示例8: OnCollisionEnter2D

 private void OnCollisionEnter2D(Collision2D other)
 {
     if (other.collider.tag == Tags.player)
     {
         other.gameObject.GetComponent<Player>().Die();
     }
 }
开发者ID:ronaldme,项目名称:Cuber-Unity,代码行数:7,代码来源:JumpingDeath.cs

示例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;
     }
 }
开发者ID:dev-celvin,项目名称:DK,代码行数:7,代码来源:HasExitedCollision2D.cs

示例10: OnCollisionStay2D

 private void OnCollisionStay2D(Collision2D collision)
 {
     if (CollisionStay2D != null)
     {
         CollisionStay2D(this, collision);
     }
 }
开发者ID:thebeardphantom,项目名称:UnityCommonLibrary,代码行数:7,代码来源:ColliderEvents2D.cs

示例11: OnCollisionEnter2D

        void OnCollisionEnter2D(Collision2D col)
        {
            if (infiniteJumps) return;

            numJumps--;
            if(numJumps == 0) StartCoroutine(Fall());
        }
开发者ID:Pavelko007,项目名称:InfiniteBall,代码行数:7,代码来源:FallingPlatform.cs

示例12: OnCollisionStay2D

 void OnCollisionStay2D(Collision2D col)
 {
     if (col.gameObject.tag == "Player")
     {
         col.gameObject.GetComponent<CharHealth>().Damage(Attack);
     }
 }
开发者ID:ShvedA,项目名称:RogueRpg1,代码行数:7,代码来源:Spider.cs

示例13: OnCollisionEnter2D

 public void OnCollisionEnter2D(Collision2D collision)
 {
     if (MainScript.SelfType == MainScript.PlayerType.Client)
     {
         MainScript.SelfPlayer.Role.HandleCollision(this, collision);
     }
 }
开发者ID:KvanNes,项目名称:Contextproject-Group5,代码行数:7,代码来源:CarBehaviour.cs

示例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);
 }
开发者ID:JonathanHunter,项目名称:ZeroScripts,代码行数:7,代码来源:Dagger.cs

示例15: OnCollisionEnter2D

    // not supported
#else
        // ReSharper disable once UnusedMember.Local
        private void OnCollisionEnter2D(Collision2D coll) {
            if (!_isValid) {
                return;
            }

            KillableToAlert.CollisionEnter2D(coll);
        }
开发者ID:timmypowergamer,项目名称:RitualShooter,代码行数:10,代码来源:KillableChildCollision.cs


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