You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.0 KiB
71 lines
2.0 KiB
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace UnityEngine.UCMobile
|
|
{
|
|
[Serializable]
|
|
public class MoveToTarget : UCMobileModel {
|
|
|
|
|
|
|
|
[SerializeField]
|
|
Settings m_Settings = Settings.defaultSettings;
|
|
|
|
[Serializable]
|
|
public struct Settings
|
|
{
|
|
[Tooltip("slow down range to target")]
|
|
public float slow_down_range;
|
|
[Tooltip("speed smooth")]
|
|
[Range(0,1)]
|
|
public float smooth;
|
|
[Tooltip("Move Target")]
|
|
public Transform target;
|
|
|
|
public static Settings defaultSettings
|
|
{
|
|
get
|
|
{
|
|
return new Settings
|
|
{
|
|
slow_down_range = 1,
|
|
smooth = 1
|
|
};
|
|
}
|
|
}
|
|
}
|
|
public Settings settings
|
|
{
|
|
get { return m_Settings; }
|
|
set { m_Settings = value; }
|
|
}
|
|
|
|
public override void DoBehavier(GameObject obj)
|
|
{
|
|
if (settings.target == null)
|
|
return;
|
|
|
|
Vector3 to_target_dir = settings.target.position - obj.transform.position;
|
|
|
|
float dist = to_target_dir.magnitude;
|
|
float dist_weight = Mathf.Min(1.0f, dist / settings.slow_down_range);
|
|
to_target_dir.Normalize();
|
|
Vector3 new_dir = (settings.target.position - obj.transform.position).normalized * (1.0f - dist_weight);
|
|
Vector3 _direction = obj.transform.forward;
|
|
_direction += (new_dir - _direction) * Mathf.Min(1.0f, Time.deltaTime / 0.1f);
|
|
_direction.Normalize();
|
|
|
|
Vector3 vel = _direction * settings.smooth * dist_weight;
|
|
obj.transform.position += vel * Time.deltaTime;
|
|
}
|
|
|
|
public override void Reset()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|