- Home /
How to create a popup after a specific level
Hi there everyone, I am trying to create a popup that will show up after completing level 15. Is there any ideas on how to code a popup to show on a specific level in C#? I tried using the following:
using UnityEngine; using System.Collections;
public class ServiceAssistant : MonoBehaviour { public static ServiceAssistant main;
public bool lifes_refilled_notification = true; public bool daily_reward_notification = true; public bool good_morning_notification = true;
bool rate_it_showed = false; bool daily_reward_showed = false;
// other lines of code for my game
// show page when level 15 is completed if (Level == 15){ UIAssistant.main.ShowPage("ItemFound"); yield break; }
Answer by ClumsyLobster · Apr 03, 2018 at 10:03 PM
SO, fundamentally you want to use the Canvas and UI system to achieve your goal. For example, display a UI screen when level = 15.
1) Create a canvas 2) Select the canvas, create an empty GameObject and call it "ExamplePopup" 3) Add some UI elements so it looks nicer.
Now, what you need to do is reference this screen and enable/disable based on whatever conditions you want.
// reference current level
public int CurrentLevel;
// reference ExamplePopup UI screen
public GameObject ExamplePopup;
void Awake() {
CurrentLevel = 1;
}
void Update() {
if (CurrentLevel == 15) {
ShowPopup();
}
}
void ShowPopup() {
ExamplePopup.SetActive(true);
}
It's a bit rough but I hope you get the idea.
https://docs.unity3d.com/ScriptReference/GameObject.SetActive.html
Your answer
Follow this Question
Related Questions
Changing scenes with unity 4.6 UI 1 Answer
How to add a popup GUI on a specific level before the Win popup? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers