This repository has been archived on 2025-09-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
XericLibrary-OLD/Runtime/SpatialTransform/OffsetFromTrackTarget.cs
2023-11-08 13:41:11 +08:00

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;
}
}
}