help make this have a delay, currently the pathfinding doesn't work



import sys
from ursina import *
import random

sys.setrecursionlimit(10000)

app = Ursina()
window.borderless = False
window.fullscreen = False

def create_map(w, h):
    return [[1 for _ in range(w)] for _ in range(h)]

def create_map_object(maze):
    maze_objects = []
    spacing = 0.1

    for i in range(len(maze)):
        maze_objects.append([])
        for j in range(len(maze[i])):
            if maze[i][j] == 1:
                maze_objects[i].append(Entity(model="cube",color=color.blue,scale=(.1, .1, .1),collider="box"))
            elif maze[i][j] == 0:
                maze_objects[i].append(Entity(model="quad",color=color.white,scale=(.1, .1, .1),collider="box",))
            elif maze[i][j] == 100:
                maze_objects[i].append(Entity(model="quad",color=color.green,scale=(.1, .1, .1),collider="box",))
            elif maze[i][j] == 999:
                maze_objects[i].append(Entity(model="quad",color=color.red,scale=(.1, .1, .1),collider="box",))
            maze_objects[i][j].y = 4 - i * spacing
            maze_objects[i][j].x = -7.15 + j * spacing
            maze_objects[i][j].parent = scene
    return maze_objects

def depth_first_search_map(x, y, maze):
    maze[y][x] = 0
    possible = [[0, 2], [2, 0], [0, -2], [-2, 0]]
    random.shuffle(possible)
    for x1, y1 in possible:
        lx1, ly1 = x + x1, y + y1
        if 0 <= lx1 < len(maze[0]) and 0 <= ly1 < len(maze) and maze[ly1][lx1] == 1:
            maze[y + y1 // 2][x + x1 // 2] = 0
            depth_first_search_map(lx1, ly1, maze)

def newMaze(maze):
    nmaze = []
    for i in range(len(maze) + 2):
        nmaze.append([])
        for j in range(len(maze[0]) + 2):
            nmaze[i].append(1)
    for i in range(1, len(nmaze) - 1):
        for j in range(1, len(nmaze[0]) - 1):
            nmaze[i][j] = maze[i - 1][j - 1]
    for i in range(1, 4):
        for j in range(1, 4):
            nmaze[i][j] = 0
    nmaze[2][2] = 100
    for i in range(48, 52):
        for j in range(48, 52):
            nmaze[i][j] = 0
    nmaze[50][50] = 999
    return nmaze

def backtrack(x, y, maze_obj, visited, tx, ty, delay=.01):
    if x == tx and y == ty:
        return True
    if (x, y) in visited:
        return False
    visited.add((x, y))
    neighbors = [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]
    for i, (nx, ny) in enumerate(neighbors):
        if 0 <= nx < len(maze_obj[0]) and 0 <= ny < len(maze_obj) and maze_obj[ny][nx].color != color.blue:
            # Add a delay between each recursive call to backtrack
            if backtrack(nx, ny, maze_obj, visited, tx, ty, delay=delay):
                return True
    visited.remove((x, y))
    return False

def invoke_with_delay(function, delay):
    def delayed_func():
        function()
    s = Sequence(
        Wait(delay),
        Func(delayed_func)
    )
    s.start()

def find_path(maze, maze_obj):
    visited = set()
    target = (50, 50)
    def backtrack_with_delay():
        backtrack(1, 1, maze_obj, visited, target[1], target[0], delay=0.01)
    invoke_with_delay(backtrack_with_delay, delay=0.01)
    return maze_obj

width = 50
height = 50
maze = create_map(width, height)
depth_first_search_map(2, 2, maze)
maze = newMaze(maze)
maze_obj = create_map_object(maze)
maze_obj = find_path(maze, maze_obj)

app.run()