Start menu in Unity - unity ui
How to make Start menu in Unity - unity ui
- Add play button .
- Add Setting button .
- Add sound button Controller .
- Add Quit button .
- Add Help button .
- Add Share button .
- Add More Game Button .
- first thing to do is designing your menu for The Home Scene .
- create a new gameObgect ,name it " MainMenuController "
- add a new script to the gameObgect MainMenuController and name it " MainMenuController "
- This script MainMenuController .cs control the main menu buttons and animations of The Home Scene .
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class MainMenuController : MonoBehaviour {
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
}
- we get the ref to our setting button animator and we have serialized field because the variable is private and we want to access it from inspector :
[SerializeField]
private Animator settingButtonAnim;
- this bool tell wheater the buttons setting button holder are hidden or not .
private bool hidden;
- this prevent the user from touching the setting button when the setting button animation is playing .
private bool canTouchSettingButtons;
- ref to music button and its sprite .
[SerializeField]
private Button musicBtn;
[SerializeField]
private Sprite[] musicBtnSprite;
private AudioSource clickSound;
- at start we check the music status and the assign the sprite to the music button and vol to game .
// Use this for initialization
void Start ()
{
//at start we check the music status and the assign the sprite to the music button and vol to game
if (GameManager.singleton.isMusicOn)
{
AudioListener.volume = 1;
musicBtn.image.sprite = musicBtnSprite[1];
}
else
{
AudioListener.volume = 0;
musicBtn.image.sprite = musicBtnSprite[0];
}
clickSound = GetComponent<AudioSource>();
//at start we want this bool to be true
canTouchSettingButtons = true;
hidden = true;
}
- in Update() is check if button is click and if yes then we play slideIn animation and wait for 1.2 sec and the we again make the button interactable .
//this is used to control the animation of setting button
IEnumerator DisableWhilePlayingSettingAnim()
{
//is check if button is click
if (canTouchSettingButtons)
{
//we check if the buttons are hidden
if (hidden)
{
//if yes then we play slideIn animation and wait for 1.2 sec and the we again make the button interactable
canTouchSettingButtons = false;
settingButtonAnim.Play("SlideIn");
hidden = false;
yield return new WaitForSeconds(1.2f);
canTouchSettingButtons = true;
}
else
{
canTouchSettingButtons = false;
settingButtonAnim.Play("SlideOut");
hidden = true;
yield return new WaitForSeconds(1.2f);
canTouchSettingButtons = true;
}
}
}
- The method which we will assign to setting button . when setting button is clicked we start out coroutine .
public void SettingBtn()
{
//when setting button is clicked we start out coroutine
StartCoroutine(DisableWhilePlayingSettingAnim());
clickSound.Play();
}
- The method which we will assign to play button .
public void PlayButton()
{
//Application.LoadLevel("ModeSelector"); // if you are using unity below 5.3 version
SceneManager.LoadScene("ModeSelector");//use this for 5.3 version
clickSound.Play();
}
- The method which we will assign to Quit Button :
public void QuitButton()
{
Application.Quit();
}
- The method which we will assign to music button :
public void MusicButton()
{
//it check the music status wheather its on of not and when we click the button it make is on or off respectively
clickSound.Play();
if (GameManager.singleton.isMusicOn)
{
AudioListener.volume = 0;
musicBtn.image.sprite = musicBtnSprite[0];
GameManager.singleton.isMusicOn = false;
GameManager.singleton.Save();
}
else
{
AudioListener.volume = 1;
musicBtn.image.sprite = musicBtnSprite[1];
GameManager.singleton.isMusicOn = true;
GameManager.singleton.Save();
}
}
- The method which we will assign to more games button :
public void MoreGameButton()
{
//here you can provide link of your other games
Application.OpenURL("http://sfgames.epizy.com/");
clickSound.Play();
}
- The method which we will assign to info button
public void InfoButton()
{//this is to provide the info on how to play game
clickSound.Play();
}
- method which we will assign to rate button :
public void RateButton()
{
//here provide the link of your game so player can rate it
Application.OpenURL("http://sfgames.epizy.com/2020/11/14/maths-game/");
clickSound.Play();
}
- To know how to make Share Button click here
...
créer un menu unity 2d,script menu unity,unity pause menu,unity ui tutorial 2020,button unity,unity ui builder,unity save,main menu ui,créer un menu unity 2d,script menu unity,unity pause menu,unity ui tutorial 2020,button unity,unity ui builder,
Post a Comment
image video quote pre code