Ai problem

I was making a Ai which jumps at random direction at a random time and it only goes in one direction

    public float speed;
    private Rigidbody2D rb;
    float jumpTime; // this value is set to random so enemy jumps in random time interval   
    float nextJumpTime;
    float jumpdir;// this is set to random so that player jumps in a random directon
    
    void Awake()
    {
        rb = GetComponent<Rigidbody2D>();
        nextJumpTime = 2;
        jumpdir = 1;
    }

    void FixedUpdate()
    {
       
        jumpTime = Random.Range(3, 7);//random time code;
        jumpdir = Random.Range(1, 2);//random direction code;
        Debug.Log(jumpdir);

        if (jumpdir ==2 && nextJumpTime < Time.time)//to jump left in random time
        {
            nextJumpTime = jumpTime + Time.time + 1f;
            rb.AddForce(new Vector2(1f, 1f) * speed, ForceMode2D.Impulse);
            Debug.Log("jumped right");
            

        }
        else if (jumpdir==1 && nextJumpTime < Time.time) // to jump right in random time
        {
            nextJumpTime = jumpTime + Time.time + 1f;
            rb.AddForce(new Vector2(-1f, 1f) * speed, ForceMode2D.Impulse);
            Debug.Log("jumped left");
            

        }
    }
}

Hi!

You are calculating a random number every frame, and every frame cheking if this number is 1 or is 2… You shouldnt do this each Update…

Anyway… You Need to debug your code when have problems like this, if you do , you will see jumpdir is always 1, never 2. Then you should go to Unity documentation and read about RAndom.Range, and will see the second value is EXCLUSIVE, sop it will never be picked, you need to do

Random.Range(1,3) to get 1 or 2.

Bye!