烤肉酱

导航

Unity添加多个可视镜头Preview功能(二)

制作好并摆放好镜头以后,在Preview.cs里添加一个time单个镜头移动时间的变量,并在PreviewEditor下绘制在Inspector面板下。

然后,添加一个FollowPreviewPath.cs的脚本,放在你需要移动的主相机下,相机就会根据你Preview的路径和时间进行移动。

 

 

 完成@_@!后续想新增一些功能再继续完善它...

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FollowPreviewPath : MonoBehaviour {
    public Camera followCamera;
    public Preview[] Previews;
    int currentPoint;
    float Clamptmp;

    Vector3 startPosition;
    Quaternion startRotation;
    // Use this for initialization
    void Start () {
        startPosition = transform.position;
        startRotation = transform.rotation;
    }

    // Update is called once per frame
    void Update()
    {
        if (currentPoint < Previews.Length)
        {
            Clamptmp = Mathf.Clamp01(Clamptmp += Time.deltaTime / Previews[currentPoint].time);
            print(Clamptmp);
            followCamera.transform.position = Vector3.Lerp(startPosition, Previews[currentPoint].transform.position, Clamptmp);
            followCamera.transform.rotation = Quaternion.Lerp(startRotation, Previews[currentPoint].transform.rotation, Clamptmp);
            if (Clamptmp == 1)
            {
                startPosition = transform.position;
                startRotation = transform.rotation;
                currentPoint += 1;
                Clamptmp = 0;
            }
        }
    }
}

 

posted on 2018-11-22 10:27  烤肉酱  阅读(598)  评论(0编辑  收藏  举报