How to make popup manager always same size and centered
How can I make the popups of this plugin be always the same size (in any type of screen) and in the same position?
The script can be located on the assetstore (https://www.assetstore.unity3d.com/en/#!/content/62666)
This is the main script:
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class PopupManager : MonoBehaviour {
public static PopupManager Instance{ set; get; }
public CanvasGroup canvasGroup;
public Text titleText;
public Text descriptionText;
private Transform uiRoot;
// Use this for initialization
void Start () {
Instance = this;
DontDestroyOnLoad (gameObject);
canvasGroup.alpha = 0;
canvasGroup.blocksRaycasts = false;
canvasGroup.interactable = false;
}
public void ShowPopup(string title, string message)
{
if (uiRoot == null)
uiRoot = GameObject.FindGameObjectWithTag ("UIRoot").transform;
transform.SetParent (uiRoot);
canvasGroup.alpha = 1;
canvasGroup.blocksRaycasts = true;
canvasGroup.interactable = true;
titleText.text = title;
descriptionText.text = message;
}
public void Onclick()
{
canvasGroup.alpha = 0;
canvasGroup.blocksRaycasts = false;
canvasGroup.interactable = false;
transform.SetParent (uiRoot.parent);
}
}
And these are the settings:
http://image.prntscr.com/image/5bdfb8ca1f3f46ccb9fedb53514217ff.jpeg
To call the popup I use:
MyNotifications.CallNotification ("Example", 2.0f);
Your answer
Follow this Question
Related Questions
Prevent expandable object from shrinking 1 Answer
Dynamic UI image scale with Text length? 0 Answers
[Beginner] [UI text] Adapt the size of the text zone to the text inside 2 Answers
Content Size Fitter doesnt work :( 0 Answers
Problem with Ui size mobile 0 Answers