41 lines
732 B
C#
41 lines
732 B
C#
using UnityEngine;
|
|
|
|
namespace Artngame.SKYMASTER
|
|
{
|
|
public class SmoothLookAtSKYMASTER : MonoBehaviour
|
|
{
|
|
public Transform target;
|
|
|
|
public float damping = 6f;
|
|
|
|
public bool smooth = true;
|
|
|
|
private Transform This_transf;
|
|
|
|
private void Start()
|
|
{
|
|
if ((bool)GetComponent<Rigidbody>())
|
|
{
|
|
GetComponent<Rigidbody>().freezeRotation = true;
|
|
}
|
|
This_transf = base.transform;
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if ((bool)target)
|
|
{
|
|
if (smooth)
|
|
{
|
|
Quaternion b = Quaternion.LookRotation(target.position - This_transf.position);
|
|
This_transf.rotation = Quaternion.Slerp(This_transf.rotation, b, Time.deltaTime * damping);
|
|
}
|
|
else
|
|
{
|
|
This_transf.LookAt(target);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|