using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using System;
|
|
|
public class DropItemTrace : MonoBehaviour
|
{
|
GActor m_Target;
|
Vector3 offset;
|
Vector3 refVelocity;
|
|
float speed = 7f;
|
float timer = 0f;
|
Action onReach;
|
|
SFXController m_Effect;
|
|
public void Trace(GActor _actor, Vector3 _offset, Action _onReach)
|
{
|
m_Target = _actor;
|
offset = _offset;
|
refVelocity = Vector3.zero;
|
onReach = _onReach;
|
timer = 0f;
|
if (m_Effect == null)
|
{
|
m_Effect = SFXPlayUtility.Instance.Play(1999, this.transform);
|
}
|
}
|
|
private void LateUpdate()
|
{
|
timer += Time.deltaTime;
|
|
if (m_Target == null || Vector3.Distance(this.transform.position, m_Target.Pos + offset) < 0.3f)
|
{
|
if (m_Effect != null)
|
{
|
SFXPlayUtility.Instance.Release(m_Effect);
|
m_Effect = null;
|
}
|
|
m_Target = null;
|
if (onReach != null)
|
{
|
onReach();
|
onReach = null;
|
}
|
}
|
else
|
{
|
speed = Mathf.Clamp(2 + timer * 4f, 2f, 7f);
|
var targetPosition = m_Target.Pos + offset;
|
var deltaPosition = (targetPosition - this.transform.position).normalized * speed * Time.deltaTime;
|
|
this.transform.position += deltaPosition;
|
}
|
|
}
|
|
|
|
}
|