using System;
using UnityEngine;
using UnityEngine.SceneManagement;

public class CharacterSelectionScript : MonoBehaviour
{
    private int selectedCharacterIndex = 0;

    private string[] characters = {"Sloane", "Cade", "LeoAndAri", "Gamma07"};
    
    private GameObject selectedCharacter;


    private int framesSinceChange = 0;

    
    void Awake()
    {
        selectedCharacter = GameObject.Find(characters[selectedCharacterIndex]);
    }


    void FixedUpdate() {
        framesSinceChange ++;

        if (framesSinceChange > 5) {   
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                CycleLeft();
            }

            
            if (Input.GetKey(KeyCode.RightArrow))
            {
                CycleRight();
            }
        }
    }

    public void CycleLeft() {
        if (selectedCharacterIndex == 0)
        {
            selectedCharacterIndex = characters.Length - 1;
        }
        else
        {
            selectedCharacterIndex --;
        }
        selectedCharacter.GetComponent<SpriteRenderer>().enabled = false;
        selectedCharacter = GameObject.Find(characters[selectedCharacterIndex]);
        selectedCharacter.GetComponent<SpriteRenderer>().enabled = true;
        framesSinceChange = 0;
    }
    public void CycleRight() {
        if (selectedCharacterIndex == characters.Length - 1)
        {
            selectedCharacterIndex = 0;
        }
        else
        {
            selectedCharacterIndex += 1;
        }
        selectedCharacter.GetComponent<SpriteRenderer>().enabled = false;
        selectedCharacter = GameObject.Find(characters[selectedCharacterIndex]);
        selectedCharacter.GetComponent<SpriteRenderer>().enabled = true;
        framesSinceChange = 0;
    }
}