36 lines
892 B
C#
36 lines
892 B
C#
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class CameraPositioner : MonoBehaviour
|
||
|
{
|
||
|
public GameObject TrackEntity;
|
||
|
public float SwitchTime;
|
||
|
|
||
|
private Vector3 _from;
|
||
|
private float _t;
|
||
|
private bool _switching;
|
||
|
|
||
|
void LateUpdate()
|
||
|
{
|
||
|
if (_switching && SwitchTime > 0)
|
||
|
{
|
||
|
transform.position = Vector3.Lerp(_from, TrackEntity.transform.position, _t);
|
||
|
var dt = Time.deltaTime / SwitchTime;
|
||
|
_t += dt;
|
||
|
if (_t >= 1)
|
||
|
{
|
||
|
_switching = false;
|
||
|
_from = TrackEntity.transform.position;
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
var dp = TrackEntity.transform.position - _from;
|
||
|
transform.position += dp;
|
||
|
_from = TrackEntity.transform.position;
|
||
|
}
|
||
|
|
||
|
// TODO(zeph): switch track entities
|
||
|
}
|