37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Events;
|
|
public class ControlSettings : MonoBehaviour
|
|
{
|
|
private const string ControlOnRightKey = "ControlOnRight";
|
|
public Button left;
|
|
public Button right;
|
|
public static bool ControlIsOnRight = true;
|
|
public UnityEvent OnChanged;
|
|
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();
|
|
OnChanged.Invoke();
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|