25 lines
597 B
C#
25 lines
597 B
C#
using UnityEngine;
|
|
|
|
public class FragmentSnapPoint : MonoBehaviour
|
|
{
|
|
public int fragmentID;
|
|
public float snapDistance = 0.25f;
|
|
|
|
private void OnTriggerStay(Collider other)
|
|
{
|
|
Fragment frag = other.GetComponent<Fragment>();
|
|
|
|
if (frag == null) return;
|
|
if (frag.isSet) return;
|
|
|
|
// ID 不匹配 → 不吸附
|
|
if (frag.id != fragmentID) return;
|
|
|
|
// 距离检测
|
|
float dis = Vector3.Distance(frag.transform.position, transform.position);
|
|
if (dis < snapDistance)
|
|
{
|
|
frag.SnapTo(transform);
|
|
}
|
|
}
|
|
} |