using UnityEngine;

public class BarreauLadder : InteractableObject {

    [SerializeField] private GameObject piedEchelle = null;

    private bool isAttachedToPlayer = false;

    private static Vector3 barreauBottomPos = new Vector3(-128.2f, 16.182f, -62.65f);

    private const float pasBarreau = 0.85f;

    private bool isPlace = false;

    protected override void Update () {
        if (!isPlace) {
            base.Update();
            if (isAttachedToPlayer) {
                transform.position = Camera.main.transform.position + Camera.main.transform.forward;
                if (Vector3.Distance(transform.position, piedEchelle.transform.position) < 3 && (Input.GetMouseButtonDown(0) || Input.GetButtonDown("Action"))) {
                    isAttachedToPlayer = false;
                    isPlace = true;
                    transform.position = barreauBottomPos + Vector3.up * pasBarreau * BrokenLadder.barreauxPlaces;
                    transform.localEulerAngles = 90 * Vector3.up;
                    BrokenLadder.barreauxPlaces++;
                }
            }
        }
	}

    protected override void DoActionDown() {
        if (!isPlace) {
            isAttachedToPlayer = true;
            isVisible = false; // Pour enlever le contour jaune quand on a pris le barreau
            myMat.shader = originalShader;
        }
    }
}