コード例 #1
0
    void collisionWithFloor(Collision2D other)
    {
        float strength = Mathf.Clamp(other.relativeVelocity.magnitude / 40f, 0, .8f);

        jumped = false;
        if (smashStateEnum != null)
        {
            if (!spriteAnim.GetAnimation().Equals("smash") &&
                !spriteAnim.GetAnimation().Equals("crush"))
            {
                chargeVisualEffects(0);
                StopCoroutine(smashStateEnum);
                smashStateEnum = null;
                StartCoroutine(recovery(SmashCooldownTime));
                checkGround();

                bounceDirection.y *= 100;
                bounceDirection.y  = Mathf.Max(50, bounceDirection.y);
                print(bounceDirection.y);
            }
            else if (other.gameObject.GetComponent <SquareBehavior>() != null)
            {
                StopCoroutine(smashStateEnum);

                if (afterImageEnum != null)
                {
                    StopCoroutine(afterImageEnum);
                }
                canSmash = false;

                if (Shake.instance != null)
                {
                    Shake.instance.shake(2, 3);
                }

                rigid.velocity = Vector3.zero;
                Color color = GetComponent <SpriteRenderer>().color;
                color.a = 0.75f;
                WaveGenerator.instance.makeWave(other.gameObject.GetComponent <SquareBehavior>().initialPosition, strength * smashPower, color, chargeValue >= maxChargeTime ? 10 : 7, centerOfGravity);

                if (smashPower > maxSmashPower / 2)
                {
                    WaveGenerator.instance.timeFreeze(0.3f, 0.15f);
                }
                audioManager.instance.Play(smash, 0.75f, UnityEngine.Random.Range(0.95f, 1.05f));
                if (FindObjectOfType <TerrainTilt>() != null)
                {
                    FindObjectOfType <TerrainTilt>().applySmashForce(this.transform.position, strength);
                }
                StartCoroutine(recovery(SmashCooldownTime));
            }
            SmashSpeed  = 0;
            smashPower  = 0;
            chargeValue = 0;

            smashStateEnum = null;

            GameObject colParticle       = Instantiate(collisionParticle, other.contacts[0].point, transform.rotation);
            ParticleSystem.MainModule ps = colParticle.GetComponent <ParticleSystem>().main;
            ps.startColor = baseColor;

            ps.startSize  = 1f;
            ps.startSpeed = 100f;

            Destroy(colParticle, 0.75f);
        }
    }