- Home /
after click a GUI button from Menu to Game there are two screens
I created a scene called Menu and declaring it to go to my scene Game when clicking on a button called Play.
When clicking on the button, with an attached button script, the game loads, however, the game shows two background layouts.
Here is the Button script that I am using to go from my Menu scene to my Game scene.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class btnNext : MonoBehaviour {
public AudioClip btnClickedSound; //audioclip for buttons
public Sprite btnActive; //sprite representing active state of button
private SpriteRenderer spriteRenderer;
private Sprite initialSprite;
// Use this for initialization
void Start () {
initialSprite = this.GetComponent<SpriteRenderer>().sprite; //save object's sprite to an initial variable
spriteRenderer = GetComponent<Renderer>() as SpriteRenderer;
}
/// Raises the mouse down event.
void OnMouseDown()
{
spriteRenderer.sprite = btnActive;
PlayAudioButtons();
}
/// Raises the mouse up event.
void OnMouseUp()
{
spriteRenderer.sprite = initialSprite; //reset the button sprite to its initial normal state
UIAssistant.main.ShowPage ("CardReward");
}
void PlayAudioButtons()
{
GetComponent<AudioSource>().PlayOneShot(btnClickedSound, 0.5f);
}
}
Answer by dinostudios123 · Apr 10, 2018 at 06:18 PM
Sorry the script is the wrong type, on the line 25, the script is to have the following:
Application.LoadLevel("Game");
other than that, the script is correct.
Your answer
Follow this Question
Related Questions
Animation Lag 0 Answers
Can't Change Scenes When Built 4 Answers
Text.text doesnt work after scene change 2 Answers
UI Scene ending with Text 1 Answer
How to make buttons have sound when it is highlighted and clicked? 0 Answers