58 lines
978 B
C#
58 lines
978 B
C#
![]() |
using UnityEngine;
|
|||
|
using G;
|
|||
|
public class Ef_TrackTarget : MonoBehaviour
|
|||
|
{
|
|||
|
public float m_rotateSpeed = 0.1f;
|
|||
|
|
|||
|
protected Ef_base m_baseScript;
|
|||
|
|
|||
|
protected EntityCha m_target;
|
|||
|
|
|||
|
private void OnStart()
|
|||
|
{
|
|||
|
m_baseScript = base.gameObject.GetComponent<Ef_base>();
|
|||
|
}
|
|||
|
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
GetTarget();
|
|||
|
}
|
|||
|
|
|||
|
private void Update()
|
|||
|
{
|
|||
|
Vector3 vector;
|
|||
|
if (m_target != null)
|
|||
|
{
|
|||
|
vector = m_target.transform.position - base.transform.position;
|
|||
|
vector[1] = 0f;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
vector = base.transform.forward;
|
|||
|
vector[1] = 0f;
|
|||
|
}
|
|||
|
base.transform.forward = Vector3.Lerp(base.transform.forward, vector.normalized, m_rotateSpeed);
|
|||
|
}
|
|||
|
|
|||
|
private void OnDisable()
|
|||
|
{
|
|||
|
m_target = null;
|
|||
|
}
|
|||
|
|
|||
|
private void GetTarget()
|
|||
|
{
|
|||
|
if (m_baseScript == null)
|
|||
|
{
|
|||
|
m_baseScript = base.gameObject.GetComponent<Ef_base>();
|
|||
|
}
|
|||
|
if (m_baseScript.m_user == null)
|
|||
|
{
|
|||
|
m_target = null;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
m_target = m_baseScript.m_user.GetComponent<EntityCha>().target;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|