admin管理员组文章数量:1122792
I have been suffering from the same problem for several days. I want to add damage to the attack motion, but I can't solve this problem. Please lend me your wisdom.
public class BaseWeapon : MonoBehaviour
{
protected WeaponSpawnerStats stats;
protected void attactEnemy(Collider2D collider2d, float attack)
{
if(!collider2d.gameObject.TryGetComponent<EnemyController>(out var enemy)) return;
float damage = enemy.Damage(attack);
spawner.TotalDamage += damage;
if (0 > stats.HP) return;
stats.HP--;
if (0 > stats.HP) Destroy(gameObject);
protected void attackEnemy(Collider2D collider2d)
{
attackEnemy(collider2d, stats.Attack);
/*
BaseWeapon.cs(59,3): error CS1501:
No overload for method 'attackEnemy' takes 2 arguments
*/
}
}
protected void attackEnemy(Collider2D collider2d)
{
attackEnemy(collider2d);
}
It works, but the attack motion will not contain any damage
I have been suffering from the same problem for several days. I want to add damage to the attack motion, but I can't solve this problem. Please lend me your wisdom.
public class BaseWeapon : MonoBehaviour
{
protected WeaponSpawnerStats stats;
protected void attactEnemy(Collider2D collider2d, float attack)
{
if(!collider2d.gameObject.TryGetComponent<EnemyController>(out var enemy)) return;
float damage = enemy.Damage(attack);
spawner.TotalDamage += damage;
if (0 > stats.HP) return;
stats.HP--;
if (0 > stats.HP) Destroy(gameObject);
protected void attackEnemy(Collider2D collider2d)
{
attackEnemy(collider2d, stats.Attack);
/*
BaseWeapon.cs(59,3): error CS1501:
No overload for method 'attackEnemy' takes 2 arguments
*/
}
}
protected void attackEnemy(Collider2D collider2d)
{
attackEnemy(collider2d);
}
It works, but the attack motion will not contain any damage
Share Improve this question edited Nov 25, 2024 at 5:02 derHugo 90.2k9 gold badges90 silver badges134 bronze badges asked Nov 21, 2024 at 22:50 noanoa 232 bronze badges1 Answer
Reset to default 1The method you are trying to call has a typo: it's called attactEnemy
(t instead of k). Updating it to attackEnemy
should fix the problem.
Your updated code attackEnemy(collider2d);
doesn't cause a compilation error because you're calling the same method recursively. It doesn't do anything though (besides wasting resources), as the method just calls itself in a loop.
本文标签: cHow do I include damage in character motionStack Overflow
版权声明:本文标题:c# - How do I include damage in character motion? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736306733a1933065.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论