示例#1
0
    void LateUpdate()
    {
        // Return if not following player or if player null
        if (!followPlayer || target == null)
        {
            return;
        }

        // Update focus area with target collider
        focusArea.UpdateFocus(targetCollider.bounds);

        // Apply center offsets
        Vector2 focusPos = focusArea.center + (Vector2.up * yOffset) + (Vector2.right * xOffset);

        // Set the focusArea position
        if (Time.deltaTime != 0)    // Avoid dividing by deltaTime 0
        {
            focusPos.y = Mathf.SmoothDamp(transform.position.y, focusPos.y, ref smoothVelocityY, smoothTimeY);
        }
        else
        {
            focusPos.y = Mathf.SmoothDamp(transform.position.y, focusPos.y, ref smoothVelocityY, smoothTimeY, Mathf.Infinity, .001f);
        }

        // Set cam position
        transform.position = new Vector3(focusPos.x, focusPos.y, -10);

        // Max y and x camera bounds
        ResetCam(transform.position);
    }