mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-09-08 02:15:16 -05:00
Added Toggle Option to Use the MLAPI Relay
- Also cleaned up and merged title screen files into a single class
This commit is contained in:
8
Assets/Scripts/UI/Options.meta
Normal file
8
Assets/Scripts/UI/Options.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 060547101a9186042a78082111fdf28b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
51
Assets/Scripts/UI/Options/OptionsMenu.cs
Normal file
51
Assets/Scripts/UI/Options/OptionsMenu.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using MLAPI.Transports.UNET;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class OptionsMenu : MonoBehaviour {
|
||||
|
||||
[SerializeField]
|
||||
private Toggle useMLAPIRelayToggle;
|
||||
|
||||
void Start() {
|
||||
// Set the current values for options
|
||||
|
||||
// ** Use MLAPI Relay
|
||||
if (PlayerPrefs.GetInt("UseMLAPIRelay") == 0) {
|
||||
useMLAPIRelayToggle.isOn = false;
|
||||
} else {
|
||||
useMLAPIRelayToggle.isOn = true;
|
||||
}
|
||||
|
||||
// Add a listener to the toggle
|
||||
useMLAPIRelayToggle.onValueChanged.AddListener((isSelected) => {
|
||||
OnUseMLAPIRelayToggleChanged(isSelected);
|
||||
});
|
||||
|
||||
// ** Other options here
|
||||
}
|
||||
|
||||
private void OnUseMLAPIRelayToggleChanged(bool newState) {
|
||||
Debug.Log("New value: " + newState);
|
||||
if (newState) {
|
||||
useMLAPIRelayToggle.isOn = true;
|
||||
PlayerPrefs.SetInt("UseMLAPIRelay", 1);
|
||||
|
||||
// Don't forget to update the value on the network manager
|
||||
GameObject.FindGameObjectWithTag("NetworkManager").GetComponent<UNetTransport>().UseMLAPIRelay = true;
|
||||
} else {
|
||||
useMLAPIRelayToggle.isOn = false;
|
||||
PlayerPrefs.SetInt("UseMLAPIRelay", 0);
|
||||
|
||||
// Don't forget to update the value on the network manager
|
||||
GameObject.FindGameObjectWithTag("NetworkManager").GetComponent<UNetTransport>().UseMLAPIRelay = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnReturnToTitleClicked() {
|
||||
SceneManager.LoadScene("TitleScene");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 992610a85a5cfc840b83ca187d0a06dc
|
||||
guid: b3ca8c571992ca54dbe057215f42f055
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
23
Assets/Scripts/UI/Title/MainMenu.cs
Normal file
23
Assets/Scripts/UI/Title/MainMenu.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class MainMenu : MonoBehaviour {
|
||||
|
||||
public void OnOptionsClicked() {
|
||||
SceneManager.LoadScene("Options");
|
||||
}
|
||||
|
||||
public void OnControlsClicked() {
|
||||
SceneManager.LoadScene("Controls");
|
||||
}
|
||||
|
||||
public void OnQuitClicked() {
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
public void OnCreditsClicked() {
|
||||
SceneManager.LoadScene("Credits");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a62a8ad6fc70a704cb8c7c644d08d3ee
|
||||
guid: a9402b1a96948474a8a65a8395afec5d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,10 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Quit : MonoBehaviour
|
||||
{
|
||||
public void Exit(){
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class toCredits : MonoBehaviour
|
||||
{
|
||||
public void ToCredits(){
|
||||
SceneManager.LoadScene("Credits");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user