代码检查:标记未在 'Tags & Layers' 中定义。
此检查会报告在 Unity 的 标签 & 层 设置中未定义的标记名称。
此检查会在如 CompareTag(...) 和 GameObject.FindWithTag(...) 等 API,以及代码将标记属性与字符串文字进行比较时显示。 如果标记不存在,调用将在运行时不会按预期工作。
示例
在此示例中,使用了 "Boss" 标记,但该标记未在项目设置中定义。
using UnityEngine;
public class Example : MonoBehaviour
{
private void Start()
{
// Reported: "Boss" tag is not defined in Tags & Layers
if (CompareTag("Boss"))
{
}
}
}
using UnityEngine;
public class Example : MonoBehaviour
{
private void Start()
{
// Use a tag that exists in the project
if (CompareTag("Player"))
{
}
}
}
快速修复
此检查不提供专用快速修复。 请手动修正标记名称或在 Unity 中创建缺失的标记来解决。
2026年 5月 8日