rabidus-test/Assets/CutsceneLookAt.cs

46 lines
959 B
C#
Raw Normal View History

2023-09-05 17:38:11 +03:00
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);
}
}