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

public class ChouYu : Creature
{
    [SerializeField] private float moveSpeed = 50f;
    private bool isDirLeft;
    private bool needTurn;

    protected override void Update()
    {
        base.Update();
        HandleMovement();
    }

    private void HandleMovement()
    {
        Vector3 curPos = transform.position;
        Vector3 moveDir;
        if(isDirLeft)
        {
            moveDir = new Vector3(-1,0,0);
        }
        else
        {
            moveDir = new Vector3(1, 0, 0);
        }
        curPos += moveDir * moveSpeed * Time.deltaTime;
        transform.position = curPos;
    }

    protected override void Start()
    {
        base.Start();

        System.Random random = new System.Random();
        isDirLeft = random.Next(2) == 0 ? false : true;
        needTurn = isDirLeft;

        if (needTurn)
        {
            HandleTurn();
        }
    }

    private void HandleTurn()
    {
        //Debug.Log("Turn");
        Quaternion quaternion = Quaternion.Euler(0,180f,0);
        transform.rotation = quaternion;
        needTurn = false;
    }
}
