コード例 #1
0
    private void OnCollisionEnter(Collision collision)
    {
        //If the player does not control, it means the level is starting
        if (!hasControls)
        {
            if (emotions)
            {
                emotions.NormalMood();
            }
            //We enable controls and start timer
            hasControls = true;
            if (handler)
            {
                handler.startRunning();
            }
            //CameraShaker.GetInstance("MainCamera").ShakeOnce(Mathf.Min(Mathf.Abs(lastVelocity.y) / 7f, 5f), 3f, 0.1f, 0.1f);
            if (bumpSource != null)
            {
                bumpSource.pitch  = Mathf.Pow(2, (Mathf.Clamp(Mathf.Abs(lastVelocity.y), 0, 100) / 100f));
                bumpSource.volume = (Mathf.Clamp(Mathf.Abs(lastVelocity.y), 0, 100) / 50f) * baseVolume;
                bumpSource.Play();
            }
            ParticleSystem.EmitParams emitOverride = new ParticleSystem.EmitParams();
            fallSparks.Emit(emitOverride, 10 + (int)Mathf.Min(Mathf.Abs(lastVelocity.y) / 5f, 20f));
        }
        /*Falldown particles*/
        if (Mathf.Abs(lastVelocity.y) > 1f)
        {
            //CameraShaker.GetInstance("MainCamera").ShakeOnce(Mathf.Min(Mathf.Abs(lastVelocity.y) / 7f, 5f), 3f, 0.1f, 0.1f);
            if (bumpSource != null)
            {
                bumpSource.pitch  = Mathf.Pow(2, (Mathf.Clamp(Mathf.Abs(lastVelocity.y), 0, 100) / 100f));
                bumpSource.volume = (Mathf.Clamp(Mathf.Abs(lastVelocity.y), 0, 100) / 50f) * baseVolume;
                bumpSource.Play();
            }


            if (Mathf.Abs(lastVelocity.y) > 5f)
            {
                if (emotions)
                {
                    emotions.Shock();
                }
                shoutHandler.PlayAudio(false);

                ParticleSystem.EmitParams emitOverride = new ParticleSystem.EmitParams();
                fallSparks.Emit(emitOverride, 10 + (int)Mathf.Min(Mathf.Abs(lastVelocity.y) / 5f, 20f));
                if (Gamepad.current != null)
                {
                    Gamepad.current.SetMotorSpeeds(1f, 1f);
                }
            }
        }

        if (Gamepad.current != null)
        {
            Gamepad.current.SetMotorSpeeds(0f, 0f);
        }
    }