This commit is contained in:
2020-07-04 14:41:25 +08:00
parent 70c346d2c1
commit a8f02e4da5
3748 changed files with 587372 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
using UnityEngine;
/// <summary>
/// Attaching this script to an object will make that object face the specified target.
/// The most ideal use for this script is to attach it to the camera and make the camera look at its target.
/// </summary>
[AddComponentMenu("NGUI/Examples/Look At Target")]
public class LookAtTarget : MonoBehaviour
{
public int level = 0;
public Transform target;
public float speed = 8f;
Transform mTrans;
void Start ()
{
mTrans = transform;
}
void LateUpdate ()
{
if (target != null)
{
Vector3 dir = target.position - mTrans.position;
float mag = dir.magnitude;
if (mag > 0.001f)
{
Quaternion lookRot = Quaternion.LookRotation(dir);
mTrans.rotation = Quaternion.Slerp(mTrans.rotation, lookRot, Mathf.Clamp01(speed * Time.deltaTime));
}
}
}
}