using UnityEngine; /// /// 挂在 touchArray 的每个子球体上,点击时把 woman 移动到 womanPointArray 对应位置。 /// 两个交叉圆环形成球形轮廓闪烁提示。 /// public class TouchPositionHandler : MonoBehaviour { public Transform targetPosition; public GameObject womanObject; public GameObject nextTouchObject; private LineRenderer _ringH; // 水平环 private LineRenderer _ringV; // 垂直环 private void Start() { var mr = GetComponent(); if (mr != null) mr.enabled = false; CreateCrossRings(); StartCoroutine(BlinkRings()); } private void CreateCrossRings() { float r = 0.15f; int segs = 32; float yOff = 0.05f; Color blue = new Color(0.2f, 0.5f, 1f); // 水平环 —— 世界空间 XZ 平面 var hGo = new GameObject("RingH"); hGo.transform.SetParent(transform, false); _ringH = hGo.AddComponent(); SetupRing(_ringH, blue); _ringH.useWorldSpace = true; _ringH.positionCount = segs; Vector3 center = transform.position + Vector3.up * yOff; for (int i = 0; i < segs; i++) { float a = i * 2f * Mathf.PI / segs; _ringH.SetPosition(i, center + new Vector3(Mathf.Cos(a) * r, 0, Mathf.Sin(a) * r)); } // 垂直环 —— 世界空间 XY 平面(竖起来) var vGo = new GameObject("RingV"); vGo.transform.SetParent(transform, false); _ringV = vGo.AddComponent(); SetupRing(_ringV, blue); _ringV.useWorldSpace = true; _ringV.positionCount = segs; for (int i = 0; i < segs; i++) { float a = i * 2f * Mathf.PI / segs; _ringV.SetPosition(i, center + new Vector3(Mathf.Cos(a) * r, Mathf.Sin(a) * r, 0)); } Debug.Log($"[TouchPosition] {name}: 交叉蓝环已创建 (r={r})"); } private void SetupRing(LineRenderer lr, Color c) { lr.loop = true; lr.startWidth = 0.06f; lr.endWidth = 0.06f; lr.material = new Material(Shader.Find("Unlit/Color")); lr.material.color = c; lr.startColor = c; lr.endColor = c; } private System.Collections.IEnumerator BlinkRings() { while (true) { bool on = !_ringH.enabled; if (_ringH != null) _ringH.enabled = on; if (_ringV != null) _ringV.enabled = on; yield return new WaitForSeconds(0.4f); } } private void OnMouseDown() { Debug.Log($"[TouchPosition] {name}: 被点击"); if (womanObject != null && targetPosition != null) { womanObject.transform.position = targetPosition.position; womanObject.transform.rotation = targetPosition.rotation; Debug.Log($"[TouchPosition] woman 移动到 {targetPosition.name}"); } else { Debug.LogWarning($"[TouchPosition] {name}: 引用为空"); } StopAllCoroutines(); if (_ringH != null) _ringH.enabled = false; if (_ringV != null) _ringV.enabled = false; gameObject.SetActive(false); if (nextTouchObject != null) { nextTouchObject.SetActive(true); Debug.Log($"[TouchPosition] {name} → {nextTouchObject.name} 显示"); } } }