Unity - 错误 CS1501:方法“#####"没有重载需要“1"个参数 [英] Unity - error CS1501: No overload for method `#####' takes `1' arguments

查看:56
本文介绍了Unity - 错误 CS1501:方法“#####"没有重载需要“1"个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行我的代码时,我一直收到这个错误,但我不太明白问题是什么:

I keep getting this error when I run my code and I can't quite see what the problem is:

错误 CS1501:方法 checkStatus 没有重载需要1"个参数

error CS1501: No overload for method checkStatus' takes `1' arguments

在我的敌人健康脚本中,我有:

In my enemyHealth script I have:

void Update() 
{
    checkStatus (0);
}

public void checkStatus()
{
    if (currentHealth > maxHealth)
        currentHealth = maxHealth;

    if (currentHealth <= 0)
        death();
}

在我的 playerAttack 脚本中,我有:

and in my playerAttack script I have:

private void Attack()
{
    enemyHealth eh = (enemyHealth)target.GetComponent ();
    eh.checkStatus (-10);
}

推荐答案

好吧,错误消息应该很简单 - 您正在使用单个参数调用 checkStatus 方法,而它声明为没有争论.

Well, the error message should be plain - you're calling the checkStatus method with a single argument, while it is declared with no arguments.

要么需要在方法声明中添加一个参数(并以某种方式使用它),要么需要将调用更改为不传递参数.

Either you need to add an argument to the method declaration (and use it somehow), or you need to change the calls to pass no argument.

您的意图似乎是降低生命值并检查角色是否幸存下来 - 如果是这样,这样的事情可能会奏效:

It seems that your intent is to either lower the health and check if the character survived - if that's the case, something like this might work:

public void Damage(int amount)
{
  currentHealth -= amount;

  if (currentHealth > maxHealth)
    currentHealth = maxHealth;

  if (currentHealth <= 0)
    death();
}

这篇关于Unity - 错误 CS1501:方法“#####"没有重载需要“1"个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆