51 lines
967 B
C#
51 lines
967 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
using XericLibrary.Runtime.Type;
|
|
|
|
namespace XericLibrary.Runtime.SpatialTransform
|
|
{
|
|
/// <summary>
|
|
/// 设定偏移来自追踪目标
|
|
/// </summary>
|
|
public class OffsetFromTrackTarget : WeaklyMonoBase
|
|
{
|
|
/// <summary>
|
|
/// 追踪目标
|
|
/// </summary>
|
|
public Transform TrackTarget;
|
|
|
|
/// <summary>
|
|
/// 偏移量
|
|
/// </summary>
|
|
public Vector3 Offset;
|
|
|
|
|
|
private void Update()
|
|
{
|
|
if(TrackTarget != null)
|
|
{
|
|
var pos = transform.position;
|
|
pos.y = 0;
|
|
var trackPos = TrackTarget.position;
|
|
trackPos.y = 0;
|
|
|
|
transform.position = TrackTarget.position + TrackTarget.rotation * Offset;
|
|
|
|
transform.rotation = Quaternion.LookRotation(pos - trackPos);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
/// <param name="tracK"></param>
|
|
public void Initialized(Transform tracK, Vector3 offset)
|
|
{
|
|
TrackTarget = tracK;
|
|
Offset = offset;
|
|
}
|
|
}
|
|
}
|