46 lines
959 B
C#
46 lines
959 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class CutsceneLookAt : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private float _speed = 5;
|
|
|
|
private Transform _target;
|
|
private bool _started = false;
|
|
|
|
public Transform Target
|
|
{
|
|
get
|
|
{
|
|
if (_target == null)
|
|
{
|
|
_target = FindObjectOfType<CutsceneLookTarget>().transform;
|
|
}
|
|
|
|
return _target;
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
_target = FindObjectOfType<CutsceneLookTarget>().transform;
|
|
}
|
|
|
|
public void StartLook()
|
|
{
|
|
_started = true;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (!_started)
|
|
return;
|
|
|
|
Vector3 targetDir = _target.position - transform.position;
|
|
targetDir.y = 0.0f;
|
|
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(targetDir), Time.time * _speed);
|
|
}
|
|
}
|