using UnityEngine;

public class SegmentController : MonoBehaviour {

    public bool isTranslucent;
    public SpriteRenderer spriteRenderer;
    private NoteColor segmentColor;

    private void Awake() {
        spriteRenderer = GetComponent<SpriteRenderer>();
    }

    private void Start() {
        isTranslucent = false;
    }

    public void setTranslucent() {
        if (isTranslucent) return;
        isTranslucent = true;
    }

    public void setOpaque() {
        if (!isTranslucent) return;
        isTranslucent = false;
    }

    private void OnTriggerExit2D(Collider2D collision) {
        if (isTranslucent) return;
        NoteController note = collision.gameObject.GetComponent<NoteController>();
        if (!note.alreadyTriggered && note.noteColor == segmentColor) {
            Debug.Log("Found note!");
            note.alreadyTriggered = true;
            note.collect();
        }
    }

    public void setColor(NoteColor color) {
        segmentColor = color;
    }
}
