dont know how to fix the problem

I finished the scripting for my game and i says that there is no suitable method to enter exit and perform and I dont know what to do. Here are all three errors and the script and the video.
Assets\Script\Enemy\States\SearchState.cs(9,26): error CS0115: ‘SearchState.Enter()’: no suitable method found to override
Assets\Script\Enemy\States\SearchState.cs(9,26): error CS0115: ‘SearchState.Perform()’: no suitable method found to override
Assets\Script\Enemy\States\SearchState.cs(9,26): error CS0115: ‘SearchState.Exit()’: no suitable method found to override
public class SearchState : MonoBehaviour
{
private float searchTimer;
private float moveTimer;
public override void Enter()
{
enemy.Agent.SetDestination(enemy.LastKnowPos);
}
public override void Perform()
{
if (enemy.CanSeePlayer())
stateMachine.ChangeState(new AttackState());

if (enemy.Agent.remainingDistance < enemy.Agent.stoppingDistance)
{
searchTimer += Time.deltaTime;
moveTimer += Time.deltaTime;
if (moveTimer > Random.Range(3, 5))
{
enemy.Agent.SetDestination(enemy.transform.position + (Random.insideUnitSphere * 10));
moveTimer = 0;
}
if (searchTimer > 10)
{
stateMachine.ChangeState(new PatrolState());
}
}
}
public override void Exit()
{

}
}

Hi,

You’re trying to override a function that is not defined inside a parent class (that is in your code MonoBehaviour, nor a parent class of MonoBehaviour)
Inside the video, the class SearchState inherits from BaseState class, so I assume methods Enter(), Perform() and Exit() are defined inside BaseState.
You either have to implement the BaseState class and inherits from it, or remove the override keyword to remove the error. (I suggest creating the BaseState class to follow the video)
Please, use code tags when you’re posting code inside forums Official - Using code tags properly - Unity Forum

1 Like