代码检查:字符串文字中引用的方法没有预期的签名
此检查会报告基于字符串的 Unity 方法引用指向签名错误的方法。
这种情况通常发生在如 Invoke、 InvokeRepeating、 StartCoroutine、 CancelInvoke 等以方法名称字符串作为参数的 Unity API 中。 方法已存在,但其参数、返回值类型或 static/实例用法与 Unity 的预期不符。
示例
在本例中, InvokeRepeating 期望无参数的实例方法,但 LaunchProjectile 声明时有一个 int 参数。
using UnityEngine;
public class Example : MonoBehaviour
{
void Start()
{
InvokeRepeating("LaunchProjectile", 1f, 1f);
}
// Reported: InvokeRepeating expects a parameterless instance method.
private void LaunchProjectile(int count)
{
}
}
using UnityEngine;
public class Example : MonoBehaviour
{
void Start()
{
InvokeRepeating("LaunchProjectile", 1f, 1f);
}
private void LaunchProjectile()
{
}
}
快速修复
此检查不会为字符串文字本身提供专用的快速修复。 需要通过将引用的方法签名更改为 Unity 所要求的签名来修正代码。
2026年 5月 8日