當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。