Hi, im trying to make some simple 2d enemy path but somehow its not working as it should, btw im using Unity and learnig C# for 5 weeks so im sorry if its like a very simple question.

so if i play game enemy is going where it should go but not doing next thing i mean going to “path2”

using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.IO;
using UnityEngine;

public class EnemyPath : MonoBehaviour
{
public Transform path1;
public Transform path2;

bool onPath1;
bool toPath1;
bool toPath2;
bool onPath2;




private void Start()
{

    toPath1 = true;
    
}

void Update()
{
    if (onPath1 == true)
    {
        this.transform.position = path1.transform.position;
        onPath2 = false;
        toPath1 = false;
        toPath2 = true;
        onPath1 = false;

    }

    

     if (onPath2 == true)
    {
        this.transform.position = path2.transform.position;
        onPath2 = false;
        toPath1 = true;
        toPath2 = false;
        onPath1 = false;
    }
    

    if (toPath1 == true)
    {
        transform.position = Vector2.MoveTowards(transform.position, path1.transform.position, 3.5f * Time.deltaTime);
        onPath2 = false;
        toPath1 = true;
        toPath2 = false;
        onPath1 = false;
    }
    

    if (toPath2 == true)
    {
        transform.position = Vector2.MoveTowards(transform.position, path2.transform.position, 3.5f * Time.deltaTime);
        onPath2 = false;
        toPath1 = false;
        toPath2 = true;
        onPath1 = false;
    }
    
    
}

}

I want to mention that game is top down without gravity if its changes anything

Let me suggest some reorganized code, I don’t think you are going to get what you want by going down this path.
**
Here I use a list of transforms to represent the path, and an int to keep track of which path waypoint we are moving towards. This helps reduce a lot of redundant code.

//Make sure you populate the pathList variable in the inspector before you run this script
public class EnemyPath : Monobehavior {
    public List<Transform>() pathList; //Here you can give it as many path waypoints as you want
    public float speed = 3.5f;
    public float entryRadius = 0.5f;
    public bool loopPath = false;
    //Keeps track of which waypoint we are going to
    private int pathIndex = 0; 

    void Update(){

        //Only move if we have a valid path index
        if(pathIndex < pathList.Count){
            transform.position = Vector2.MoveTowards(transform.position, pathList[pathIndex], speed * Time.deltaTime);

            //If we are close enough to our current target, move to the next target in the list
            if(Vector3.Distance(transform.position, pathList[pathIndex].position) <= entryRadius){
                pathIndex ++;
            }
        } 
        else if(loopPath){
            pathIndex = 0;
        }


    }
}