UPF/Assets/Game/Scripts/ControlSettings.cs
2022-12-12 23:15:36 +05:30

35 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ControlSettings : MonoBehaviour
{
private const string ControlOnRightKey = "ControlOnRight";
public Button left;
public Button right;
public static bool ControlIsOnRight = true;
void Awake()
{
if(PlayerPrefs.HasKey(ControlOnRightKey)){
ControlIsOnRight = PlayerPrefs.GetInt(ControlOnRightKey) == 1;
}
left.onClick.AddListener(()=>{ChangeControlSide(true);});
right.onClick.AddListener(()=>{ChangeControlSide(false);});
UpdateSettingsPage();
}
void ChangeControlSide(bool value){
ControlIsOnRight = value;
PlayerPrefs.SetInt(ControlOnRightKey, value? 1: 0);
PlayerPrefs.Save();
UpdateSettingsPage();
AudioManager.instnace.UIClick();
}
void UpdateSettingsPage(){
left.transform.GetChild(0).GetComponent<Image>().color = (!ControlIsOnRight) ? Color.blue : Color.green;
right.transform.GetChild(0).GetComponent<Image>().color = (ControlIsOnRight) ? Color.blue : Color.green;
}
}