Cannot set the MovementSpeed of the Attacker

Edit. I found the problem. I had the SetMovementSpeed function twice in my code. Only realised that after posting about it here. Feel really stupid at the moment. No need to help anymore :smiley:

Hi!

For some reason the I cannot set the movement speed of an attacker to 0 when the attack animation starts. I am able to set an animation event at the start of the attack animation but when I choose the SetMovementSpeed function from the dropdown list, Unity won’t allow me to choose the speed. Instead of having the option to change the speed parameter it only has this text:

“Some functions were overloaded in monobehaviour components and may not work as intended is used with animation events”.

However, if choose the DealDamage option, Unity allows me to change the value of the float parameter. With SetMovementSpeed I am unable to do that.

Here’s the code from my Atttacker Script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Attacker : MonoBehaviour
{
[Range (0f, 5f)]
float currentSpeed = 1f;

void Update()
{
    transform.Translate(Vector2.left * currentSpeed * Time.deltaTime);
}

public void SetMovementSpeed()
{
    
}

public void SetMovementSpeed (float speed)
{
    currentSpeed = speed;
}

}

Any ideas what might be causing this and what is the fix? Thanks!

Thanks for posting your solution. Next time, feel free to reply in your thread and mark your answer as the solution. :slight_smile:

No need to feel stupid. You found the issue, didn’t you? We learn best by doing mistakes and solving them if possible. Next time you get this error, you’ll know where to look first. :slight_smile:

As a side note, in terms of C#, multiple methods with the same name but different parameters are possible and used. Unity is a special case with its own rules, though, so we cannot always do what we would have done if we wrote pure C# scripts. As it seems, the Animation cannot distinguish between the methods. I didn’t know that, so this is a mistake I could have made, too.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms