Random AI walking

I’m quite a beginner in scripting. And I can’t find anything on google that helps. I want to create a random movement with the AI, this is what I have put together so far, but the enemy does not move with this.
What should be done differently?
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class Mushroom_Dmg : MonoBehaviour

{

GameObject player;

NavMeshAgent agent;

[SerializeField] LayerMask groundLayer, playerLayer;

//patrol
Vector3 desPoint;
bool walkpointSet;
[SerializeField] float range;

//state change
[SerializeField] Vector3 sightRange, attackRange;
bool playerInSight, playerInAttackRange;


void Start()
{
    
    agent = GetComponent<NavMeshAgent>();
    player = GameObject.Find("Player");
}


void Update()
{

    playerInSight = Physics.CheckCapsule(transform.position, sightRange, playerLayer);
    playerInAttackRange = Physics.CheckCapsule(transform.position, attackRange, playerLayer);

    if (!playerInSight && !playerInAttackRange) Patrol();
    if (playerInSight && !playerInAttackRange) Chase();
    if (playerInSight && playerInAttackRange) Attack();
}

void Chase()
{
    agent.SetDestination(player.transform.position);
}

void Attack()
{
}
void Patrol()
{
    if (!walkpointSet) SearchForDest() ;
    if (walkpointSet) agent.SetDestination(desPoint);
    if (Vector3.Distance(transform.position, desPoint) < 10) walkpointSet = false;
}
void SearchForDest()
{
    float z = Random.Range(-range, range);
    float x = Random.Range(-range, range);

    desPoint = new Vector3(transform.position.x + x, transform.position.y, transform.position.z + z);

    if (Physics.Raycast(desPoint, Vector3.down, groundLayer))
    {
        walkpointSet = true;
    }
}

}
}

If the character is not moving at all then (most likely) the SetDestination is never being called. It’s wrapped inside multiple if statements, so if all of the conditions are not met than that method be called.

You should use Debug.Log to find out what all of your conditions evaluate to and whether SetDestination is actually happens and why.

Edit: of course, another possibility is that the location you are passing to SetDesitination is not on the Navmesh or is unreachable by the navmesh agent. In this case, though, I believe you should get a warning in the console. The same if your navmesh agent is not on the navmesh.