using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static UnityEngine.GraphicsBuffer;

public class PlayerRope : MonoBehaviour
{
    public LineRenderer line;
    public Enemy targetEnemy;

    public int playerId;

    public void BeLink(Enemy enemy)
    {
        targetEnemy = enemy;
        gameObject.SetActive(true);
    }

    private void Update()
    {
        if (!targetEnemy)
        {
            Debug.LogError("NoTargetEnemy");
            gameObject.SetActive(false);
            return;
        }
        line.SetPosition(0, PlayersInput.instance[playerId].transform.position + Vector3.up);
        line.SetPosition(1, targetEnemy.transform.position + Vector3.up);

    }

    private void FixedUpdate()
    {
        if (!targetEnemy || targetEnemy.isDie)
        {
            gameObject.SetActive(false);
        }
    }
}
