tank follow camera

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

public class Camera_Follow_Zoom : MonoBehaviour {

    public Transform target;

    public float distanceUp = 5f;

    public float distanceAway = 5f;

    public float smooth = 2f;//position smooth movement value

    public float camDepthSmooth = 2f;

    // Use this for initialization

    void Start () {

}

// Update is called once per frame

void Update()

    {

        // The mouse axis controls the distance of the camera

        if ((Input.mouseScrollDelta.y < 0 && Camera.main.fieldOfView >= 3) || Input.mouseScrollDelta.y > 0 && Camera.main.fieldOfView <= 80)

        {

            Camera.main.fieldOfView += Input.mouseScrollDelta.y * camDepthSmooth * Time.deltaTime;

        }

 

    }

 

    void LateUpdate()

    {

        //The position of the camera

        Vector3 disPos = target.position + Vector3.up * distanceUp - target.forward * distanceAway;

        transform.position = Vector3.Lerp(transform.position, disPos, Time.deltaTime * smooth);

        // camera angle

        transform.LookAt(target.position);

    }

}

Guess you like

Origin blog.csdn.net/qq_23231303/article/details/77998456