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

public class PlayerController : MonoBehaviour
{
    [SerializeField] float speed = 1f;
    [SerializeField] GameObject eat = null;

    private Rigidbody2D rb;
    bool hasEat = false;

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    private void FixedUpdate()
    {
        var move = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);
        rb.MovePosition(rb.transform.position + move * speed * Time.fixedDeltaTime);
    }

    private void OnTriggerEnter2D(Collider2D otherCollider)
    {
        if (otherCollider.gameObject.name == "EatGenerator" && hasEat != true)
        {
            Debug.Log("Eat!!!");
            GameObject e = Instantiate(eat, transform.position, Quaternion.identity);
            e.transform.SetParent(transform);
            hasEat = true;
        }
    }

    public void ResetEat()
    {
        hasEat = false;
    }
}
