Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question dont know how to fix the problem

Discussion in 'Getting Started' started by Notit44, May 22, 2024.

  1. Notit44

    Notit44

    Joined:
    Mar 22, 2024
    Posts:
    5
    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()
    {

    }
    }
     
  2. Reaktion

    Reaktion

    Joined:
    Nov 8, 2019
    Posts:
    54
    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
     
    MCF24 likes this.