コード例 #1
0
    private void Update()
    {
        //Handling grind sparks. If the player is too fast and touching the ground
        RaycastHit hit;
        var        grindEmission         = grindSparks.emission;
        Vector3    direction             = Physics.gravity;
        bool       isEmittingGrindSparks = false;

        if (Physics.Raycast(transform.position, direction, out hit, 0.67f) && playerSpeed.value > 50f)
        {
            isEmittingGrindSparks      = true;
            grindEmission.rateOverTime = Mathf.Min(Mathf.Max((playerSpeed.value - 50f), 0f) / 2f, 20f);

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


        grindEmission.enabled = isEmittingGrindSparks;



        //Handling speed particles
        bool isEmittingSpeedSparks = false;

        ParticleSystem.EmissionModule emission = speedSparks.emission;
        if (playerSpeed.value >= 60f)
        {
            //CameraShaker.GetInstance("MainCamera").ShakeOnce(Mathf.Min((playerSpeed.value-40f)/100f,0.3f), 4f, 0.1f, 0.1f);
            isEmittingSpeedSparks = true;
            if (Gamepad.current != null)
            {
                Gamepad.current.SetMotorSpeeds(0.2f, 0.2f);
            }

            if (playerSpeed.value > 80f)
            {
                if (emotions)
                {
                    emotions.Roll();
                }
            }
            else
            {
                if (emotions)
                {
                    emotions.StopRolling();
                }
            }
        }
        else
        {
            if (Gamepad.current != null)
            {
                Gamepad.current.SetMotorSpeeds(0f, 0f);
            }
        }
        emission.rateOverTime = Mathf.Min(Mathf.Max((playerSpeed.value - 40f), 0f) / 5f, 15f);
        emission.enabled      = isEmittingSpeedSparks;



        //Handling being scared when on the border of platform
        if (isPlayerOnBorder())
        {
            if (!isLookingDown)
            {
                emotions.ReallyWorried();

                for (int i = 0; i < eyes.Length; i++)
                {
                    eyes[i].localEulerAngles = (new Vector3(20, 180, 0));
                }
                isLookingDown = true;
            }


            //lookAtTransform.localPosition =
        }
        else
        {
            if (isLookingDown)
            {
                for (int i = 0; i < eyes.Length; i++)
                {
                    eyes[i].localEulerAngles = (new Vector3(0, 180, 0));
                }
                isLookingDown = false;
                emotions.NormalMood();
            }
        }
    }