Exemplo n.º 1
0
        // Update is called once per frame
        void Update()
        {
            Shake();

            float wantedZoom      = defaultZoom;
            float wantedZoomOrtho = cam.orthographicSize;

            UnitPlayer player = GameControl.GetPlayer();

            if (player != null)
            {
                Vector3 targetPos = player.thisT.position + posOffset;

                //if enabled limit is enabled, clamp the position so it wont go out of bound
                if (enableLimit)
                {
                    targetPos.x = Mathf.Clamp(targetPos.x, minPosX, maxPosX);
                    targetPos.z = Mathf.Clamp(targetPos.z, minPosZ, maxPosZ);
                }

                //lerp to target's position
                thisT.position = Vector3.Lerp(thisT.position, targetPos, Time.deltaTime * trackSpeed);

                //adjust wanted zoom level based on player speed
                wantedZoom      = defaultZoom * (1 + (player.GetVelocity() / zoomNormalizeFactor));
                wantedZoomOrtho = defaultZoomOrtho * (1 + (player.GetVelocity() / zoomNormalizeFactor));
            }

            //if dynamicZoom is enabled, adjust the zoom acording to wanted zoom level
            if (enableDynamicZoom)
            {
                camT.localPosition   = new Vector3(0, 0, Mathf.Lerp(camT.localPosition.z, wantedZoom, Time.deltaTime * zoomSpeed));
                cam.orthographicSize = Mathf.Lerp(cam.orthographicSize, wantedZoomOrtho, Time.deltaTime * zoomSpeed);
            }
        }
Exemplo n.º 2
0
        void Update()
        {
            player = GameControl.GetPlayer();

            if (player != null && playMoveIdleSound)
            {
                if (player.GetVelocity() > 0.15f)
                {
                    if (playerMoveClip != null)
                    {
                        if (moveIdleAudioSource.clip != playerMoveClip)
                        {
                            moveIdleAudioSource.clip = playerMoveClip;
                            moveIdleAudioSource.Play();
                        }
                        else
                        {
                            if (!moveIdleAudioSource.isPlaying)
                            {
                                moveIdleAudioSource.Play();
                            }
                        }
                    }
                    else if (moveIdleAudioSource.isPlaying)
                    {
                        moveIdleAudioSource.Stop();
                    }
                }
                else
                {
                    if (playerIdleClip != null)
                    {
                        if (moveIdleAudioSource.clip != playerIdleClip)
                        {
                            moveIdleAudioSource.clip = playerIdleClip;
                            moveIdleAudioSource.Play();
                        }
                        else
                        {
                            if (!moveIdleAudioSource.isPlaying)
                            {
                                moveIdleAudioSource.Play();
                            }
                        }
                    }
                    else
                    {
                        if (moveIdleAudioSource.isPlaying)
                        {
                            moveIdleAudioSource.Stop();
                        }
                    }
                }
            }
        }