using System.Collections; using System.Collections.Generic; using Assets.Scripts.Movements; using UnityEngine; public class MovementGen : MonoBehaviour { private Dictionary components; private ChoiceOfMovement currentMovement; [SerializeField] private ChoiceOfMovement selectedMovement; // Start is called before the first frame update void Start() { components = new Dictionary(); components.Add(ChoiceOfMovement.wasd, this.GetComponent()); components.Add(ChoiceOfMovement.teleport, this.GetComponent()); components.Add(ChoiceOfMovement.joystick, this.GetComponent()); components.Add(ChoiceOfMovement.joycon, this.GetComponent()); components.Add(ChoiceOfMovement.omni, this.GetComponent()); selectedMovement = (ChoiceOfMovement)PlayerPrefs.GetInt("mouvement", 0); currentMovement = (ChoiceOfMovement)PlayerPrefs.GetInt("mouvement", 0); components[currentMovement].enabled = true; } // Update is called once per frame void FixedUpdate() { if(selectedMovement != currentMovement) { if (components[currentMovement] is IScriptDeMovement) { ((IScriptDeMovement) components[currentMovement]).BeforeDisable(); } components[currentMovement].enabled = false; components[selectedMovement].enabled = true; currentMovement = selectedMovement; } } public void ChangeMovement(ChoiceOfMovement newChoice) { selectedMovement = newChoice; } public enum ChoiceOfMovement { wasd = 0, teleport = 1, joystick = 2, joycon = 3, omni = 4 } }