using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AI: MonoBehaviour {
    
    [SerializeField]
    float walkSpeed = 2.0f;
    [SerializeField]
    float wallLeft = 0.0f;
    [SerializeField]
    float wallRight = 5.0f;
    float walkingDirection = 1.0f;
    Vector3 walkAmount;

    
    void Update() {
        walkAmount.x = walkingDirection * walkSpeed * Time.deltaTime;
        if(walkingDirection > 0.0f && transform.position.x >= wallRight) {
            walkingDirection = -1.0f;
            transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
        } else if(walkingDirection < 0.0f && transform.position.x <= wallLeft) {
            walkingDirection = 1.0f;
            transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
        }
        transform.Translate(walkAmount);
    }
}
