You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity拖拽放置系统判定异常:任意槽位均显示正确

问题修复方案

你的问题核心是判断逻辑用错了对比对象:你现在拿当前槽位(gameObject)和手动挂载的otherObject标签对比,但这个otherObject根本不是玩家拖拽过来的物体,且大概率你没给这个变量正确赋值,所以才会一直返回true。

修复步骤

直接修改ItemSlot.cs里的OnDrop方法,把对比对象换成玩家实际拖拽的物体(即eventData.pointerDrag):

修正后的ItemSlot.cs关键代码

public void OnDrop(PointerEventData eventData) {
    correctLetter = false;

    Debug.Log("OnDrop");
    if (eventData.pointerDrag != null) {
        eventData.pointerDrag.GetComponent<RectTransform>().anchoredPosition = GetComponent<RectTransform>().anchoredPosition;

        // 改为拿拖拽物体的标签和当前槽位的标签对比
        if (gameObject.tag == eventData.pointerDrag.tag) {
            correctLetter = true;
            Debug.Log("Correct Letter");
        } else {
            correctLetter = false;
            Debug.Log("Wrong Letter"); // 新增错误日志方便调试
        }
    }
}

额外注意事项

  • 确保每个拖拽图片和对应的正确槽位设置完全相同的标签(比如图片A和槽位A都设为Tag_A),Unity标签区分大小写,注意拼写一致。
  • 删除ItemSlot里无用的otherObject变量,避免代码混淆。
  • 测试时通过Unity控制台的Debug日志,确认标签匹配逻辑是否正常触发。

内容的提问来源于stack exchange,提问作者shiichiire

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 02:42:45