コード例 #1
0
ファイル: Shell.cs プロジェクト: VenzellCoder/CSharpGames
        // Create explosions on collision
        private void OnCollisionEnter(Collision c)
        {
            if (m_Exploded)
            {
                return;
            }

            //Determine the collision's normal, position, and which explosion definition to use based on how many bounces we have left.
            Vector3           explosionNormal   = c.contacts.Length > 0 ? c.contacts[0].normal : Vector3.up;
            Vector3           explosionPosition = c.contacts.Length > 0 ? c.contacts[0].point : transform.position;
            ExplosionSettings settings          = m_Bounces > 0 ? m_BounceExplosionSettings : m_ExplosionSettings;

            if (ExplosionManager.s_InstanceExists)
            {
                ExplosionManager em = ExplosionManager.s_Instance;
                if (settings != null)
                {
                    em.SpawnExplosion(transform.position, explosionNormal, gameObject, m_OwningPlayerId, settings, false);
                }
                ExplosionManager.SpawnDebris(explosionPosition, explosionNormal, m_OwningPlayerId, c.collider, m_SpawnedDebris, m_RandSeed);
            }

            //If we're bouncing, reflect our movement direction, decay our force, reduce our number of bounces.
            if (m_Bounces > 0)
            {
                m_Bounces--;

                Vector3 refl = Vector3.Reflect(-c.relativeVelocity, explosionNormal);
                refl *= m_BounceForceDecay;
                refl += m_BounceAdditionalForce;
                // Push us back up
                m_CachedRigidBody.velocity = refl;

                // Temporarily ignore collisions with this object
                if (m_TempIgnoreCollider != null)
                {
                    Physics.IgnoreCollision(GetComponent <Collider>(), m_TempIgnoreCollider, false);
                }
                m_TempIgnoreCollider     = c.collider;
                m_TempIgnoreColliderTime = m_IgnoreColliderFixedFrames;
            }
            else
            {
                Destroy(gameObject);
            }

            m_Exploded = true;
        }