Create Menu
I have implemented the menu and in case of death, it will throw the player onto the menu stage.
This commit is contained in:
8
Assets/Crossy Road VR/Scenes/Menu/Scripts/Menu.meta
Normal file
8
Assets/Crossy Road VR/Scenes/Menu/Scripts/Menu.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8bb80d7fa5e17064493146fee92d49b7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,76 @@
|
||||
using UnityEngine.Audio;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
//Credit to Brackeys youtube tutorial on Audio managers, as the majority of this code and learning how to use it was made by him.
|
||||
[System.Serializable]
|
||||
public class Sound
|
||||
{
|
||||
public string name;
|
||||
public AudioClip clip;
|
||||
[Range(0,1)]
|
||||
public float volume = 1;
|
||||
[Range(-3,3)]
|
||||
public float pitch = 1;
|
||||
public bool loop = false;
|
||||
public AudioSource source;
|
||||
|
||||
public Sound()
|
||||
{
|
||||
volume = 1;
|
||||
pitch = 1;
|
||||
loop = false;
|
||||
}
|
||||
}
|
||||
|
||||
public class AudioManager : MonoBehaviour
|
||||
{
|
||||
public Sound[] sounds;
|
||||
|
||||
public static AudioManager instance;
|
||||
//AudioManager
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (instance == null)
|
||||
instance = this;
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
foreach (Sound s in sounds)
|
||||
{
|
||||
if(!s.source)
|
||||
s.source = gameObject.AddComponent<AudioSource>();
|
||||
|
||||
s.source.clip = s.clip;
|
||||
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
s.source.loop = s.loop;
|
||||
}
|
||||
}
|
||||
|
||||
public void Play(string name)
|
||||
{
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null)
|
||||
{
|
||||
Debug.LogWarning("Sound: " + name + " not found");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.Play();
|
||||
}
|
||||
|
||||
public void Stop(string name)
|
||||
{
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
|
||||
s.source.Stop();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0dc44c5eb69748a45b697397b0740ef1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
62
Assets/Crossy Road VR/Scenes/Menu/Scripts/Menu/FadeScreen.cs
Normal file
62
Assets/Crossy Road VR/Scenes/Menu/Scripts/Menu/FadeScreen.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FadeScreen : MonoBehaviour
|
||||
{
|
||||
public bool fadeOnStart = true;
|
||||
public float fadeDuration = 2;
|
||||
public Color fadeColor;
|
||||
public AnimationCurve fadeCurve;
|
||||
public string colorPropertyName = "_Color";
|
||||
private Renderer rend;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
rend = GetComponent<Renderer>();
|
||||
rend.enabled = false;
|
||||
|
||||
if (fadeOnStart)
|
||||
FadeIn();
|
||||
}
|
||||
|
||||
public void FadeIn()
|
||||
{
|
||||
Fade(1, 0);
|
||||
}
|
||||
|
||||
public void FadeOut()
|
||||
{
|
||||
Fade(0, 1);
|
||||
}
|
||||
|
||||
public void Fade(float alphaIn, float alphaOut)
|
||||
{
|
||||
StartCoroutine(FadeRoutine(alphaIn,alphaOut));
|
||||
}
|
||||
|
||||
public IEnumerator FadeRoutine(float alphaIn,float alphaOut)
|
||||
{
|
||||
rend.enabled = true;
|
||||
|
||||
float timer = 0;
|
||||
while(timer <= fadeDuration)
|
||||
{
|
||||
Color newColor = fadeColor;
|
||||
newColor.a = Mathf.Lerp(alphaIn, alphaOut, fadeCurve.Evaluate(timer / fadeDuration));
|
||||
|
||||
rend.material.SetColor(colorPropertyName, newColor);
|
||||
|
||||
timer += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
Color newColor2 = fadeColor;
|
||||
newColor2.a = alphaOut;
|
||||
rend.material.SetColor(colorPropertyName, newColor2);
|
||||
|
||||
if(alphaOut == 0)
|
||||
rend.enabled = false;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c2d507c3ae9dc744a28e79d568b5806
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,58 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GameStartMenu : MonoBehaviour
|
||||
{
|
||||
[Header("UI Pages")]
|
||||
public GameObject mainMenu;
|
||||
|
||||
[Header("Main Menu Buttons")]
|
||||
public Button startButton;
|
||||
public Button quitButton;
|
||||
|
||||
void Start()
|
||||
{
|
||||
EnableMainMenu();
|
||||
|
||||
//Hook events
|
||||
startButton.onClick.AddListener(StartGame);
|
||||
quitButton.onClick.AddListener(QuitGame);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void QuitGame()
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
public void StartGame()
|
||||
{
|
||||
HideAll();
|
||||
SceneTransitionManager.singleton.GoToSceneAsync(1);
|
||||
}
|
||||
|
||||
public void HideAll()
|
||||
{
|
||||
mainMenu.SetActive(false);
|
||||
|
||||
}
|
||||
|
||||
public void EnableMainMenu()
|
||||
{
|
||||
mainMenu.SetActive(true);
|
||||
|
||||
}
|
||||
public void EnableOption()
|
||||
{
|
||||
mainMenu.SetActive(false);
|
||||
|
||||
}
|
||||
public void EnableAbout()
|
||||
{
|
||||
mainMenu.SetActive(false);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af07645f3014a1347a5b1232afc24251
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,64 @@
|
||||
Shader "Custom/GradientSkybox" {
|
||||
|
||||
Properties {
|
||||
_Color2 ("Top Color", Color) = (0.97, 0.67, 0.51, 0)
|
||||
_Color1 ("Bottom Color", Color) = (0, 0.7, 0.74, 0)
|
||||
|
||||
[Space]
|
||||
_Intensity ("Intensity", Range (0, 2)) = 1.0
|
||||
_Exponent ("Exponent", Range (0, 3)) = 1.0
|
||||
|
||||
[HideInInspector]
|
||||
_Direction ("Direction", Vector) = (0, 1, 0, 0)
|
||||
}
|
||||
|
||||
CGINCLUDE
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata {
|
||||
float4 position : POSITION;
|
||||
float3 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f {
|
||||
float4 position : SV_POSITION;
|
||||
float3 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
half4 _Color1;
|
||||
half4 _Color2;
|
||||
half3 _Direction;
|
||||
half _Intensity;
|
||||
half _Exponent;
|
||||
|
||||
v2f vert (appdata v) {
|
||||
v2f o;
|
||||
o.position = UnityObjectToClipPos(v.position);
|
||||
o.texcoord = v.texcoord;
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : COLOR {
|
||||
half d = dot(normalize(i.texcoord), _Direction) * 0.5f + 0.5f;
|
||||
return lerp (_Color1, _Color2, pow(d, _Exponent)) * _Intensity;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
SubShader {
|
||||
Tags { "RenderType"="Background" "Queue"="Background" }
|
||||
|
||||
Pass {
|
||||
ZClip False
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
Fog { Mode Off }
|
||||
CGPROGRAM
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f870c618efe6c2d499bb28b864be41a9
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,54 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class SceneTransitionManager : MonoBehaviour
|
||||
{
|
||||
public FadeScreen fadeScreen;
|
||||
public static SceneTransitionManager singleton;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (singleton && singleton != this)
|
||||
Destroy(singleton);
|
||||
|
||||
singleton = this;
|
||||
}
|
||||
|
||||
public void GoToScene(int sceneIndex)
|
||||
{
|
||||
StartCoroutine(GoToSceneRoutine(sceneIndex));
|
||||
}
|
||||
|
||||
IEnumerator GoToSceneRoutine(int sceneIndex)
|
||||
{
|
||||
fadeScreen.FadeOut();
|
||||
yield return new WaitForSeconds(fadeScreen.fadeDuration);
|
||||
|
||||
//Launch the new scene
|
||||
SceneManager.LoadScene(sceneIndex);
|
||||
}
|
||||
|
||||
public void GoToSceneAsync(int sceneIndex)
|
||||
{
|
||||
StartCoroutine(GoToSceneAsyncRoutine(sceneIndex));
|
||||
}
|
||||
|
||||
IEnumerator GoToSceneAsyncRoutine(int sceneIndex)
|
||||
{
|
||||
fadeScreen.FadeOut();
|
||||
//Launch the new scene
|
||||
AsyncOperation operation = SceneManager.LoadSceneAsync(0);
|
||||
operation.allowSceneActivation = false;
|
||||
|
||||
float timer = 0;
|
||||
while(timer <= fadeScreen.fadeDuration && !operation.isDone)
|
||||
{
|
||||
timer += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
operation.allowSceneActivation = true;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b29c9ee5eccc9a42a33231645d21941
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.XR.CoreUtils;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
public class SetOptionFromUI : MonoBehaviour
|
||||
{
|
||||
public Scrollbar volumeSlider;
|
||||
public TMPro.TMP_Dropdown turnDropdown;
|
||||
public SetTurnTypeFromPlayerPref turnTypeFromPlayerPref;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
volumeSlider.onValueChanged.AddListener(SetGlobalVolume);
|
||||
turnDropdown.onValueChanged.AddListener(SetTurnPlayerPref);
|
||||
|
||||
if (PlayerPrefs.HasKey("turn"))
|
||||
turnDropdown.SetValueWithoutNotify(PlayerPrefs.GetInt("turn"));
|
||||
}
|
||||
|
||||
public void SetGlobalVolume(float value)
|
||||
{
|
||||
AudioListener.volume = value;
|
||||
}
|
||||
|
||||
public void SetTurnPlayerPref(int value)
|
||||
{
|
||||
PlayerPrefs.SetInt("turn", value);
|
||||
turnTypeFromPlayerPref.ApplyPlayerPref();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8897d0c3fbd45634fb65a3a92dee951d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,38 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
public class SetTurnTypeFromPlayerPref : MonoBehaviour
|
||||
{
|
||||
public ActionBasedSnapTurnProvider snapTurn;
|
||||
public ActionBasedContinuousTurnProvider continuousTurn;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
ApplyPlayerPref();
|
||||
}
|
||||
|
||||
public void ApplyPlayerPref()
|
||||
{
|
||||
if(PlayerPrefs.HasKey("turn"))
|
||||
{
|
||||
int value = PlayerPrefs.GetInt("turn");
|
||||
if(value == 0)
|
||||
{
|
||||
snapTurn.leftHandSnapTurnAction.action.Enable();
|
||||
snapTurn.rightHandSnapTurnAction.action.Enable();
|
||||
continuousTurn.leftHandTurnAction.action.Disable();
|
||||
continuousTurn.rightHandTurnAction.action.Disable();
|
||||
}
|
||||
else if(value == 1)
|
||||
{
|
||||
snapTurn.leftHandSnapTurnAction.action.Disable();
|
||||
snapTurn.rightHandSnapTurnAction.action.Disable();
|
||||
continuousTurn.leftHandTurnAction.action.Enable();
|
||||
continuousTurn.rightHandTurnAction.action.Enable();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5fc6632ed707ab4698ecc7d2baf862f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
35
Assets/Crossy Road VR/Scenes/Menu/Scripts/Menu/UIAudio.cs
Normal file
35
Assets/Crossy Road VR/Scenes/Menu/Scripts/Menu/UIAudio.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class UIAudio : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
public string clickAudioName;
|
||||
public string hoverEnterAudioName;
|
||||
public string hoverExitAudioName;
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if(clickAudioName != "")
|
||||
{
|
||||
AudioManager.instance.Play(clickAudioName);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (hoverEnterAudioName != "")
|
||||
{
|
||||
AudioManager.instance.Play(hoverEnterAudioName);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (hoverExitAudioName != "")
|
||||
{
|
||||
AudioManager.instance.Play(hoverExitAudioName);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e419a4d4b65dfb94bae6eddedee04926
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user