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

public class GreenEnemy : MonoBehaviour
{
    public bool goLeftInit  = false;

    public float speedInit;

    private float currentSpeed;
    // Start is called before the first frame update
    void Start()
    {
        currentSpeed = goLeftInit ? -speedInit: speedInit; 
    }

    // Update is called once per frame
    void Update()
    {
        transform.position = new Vector3(currentSpeed * Time.deltaTime + transform.position.x, transform.position.y,
            transform.position.z);
    }

    void OnCollisionEnter2D(Collision2D coll) {
        if (coll.gameObject.tag == "Wall") {
            currentSpeed = -currentSpeed; 
        }
    }
}
