EN VI

Unity Game Show Popup Modal When Click Model Object Without Button

Hello. Here is sampe create popup modal to show when click object on unity game development~


- You must add Pannel to create something for your modal:



- Next, you must add Event System to listent event on your project:



-  Next, Create ShowPopupInfoWithFarmerScript.cs file with script like this:

namespace MainScript {

using UnityEngine;
using UnityEngine.UI;

public class ShowPopupInfoWithFarmerScript : MonoBehaviour
{
public GameObject popupInfoWithFarmer;
public string key;

private void OnMouseDown ()
{
Debug.LogError("ff");
if (popupInfoWithFarmer == null) {
Debug.LogError("popupInfoWithFarmer is null");
return;
}

if (string.IsNullOrEmpty(key)) {
Debug.LogError("key is null or empty");
return;
}

PopupInfoWithFarmerController popupInfoWithFarmerController = popupInfoWithFarmer.GetComponent<PopupInfoWithFarmerController>();

if (popupInfoWithFarmerController == null) {
Debug.LogError("PopupInfoWithFarmerController is null");
return;
}

// popupInfoWithFarmerController.SetKey(key);
popupInfoWithFarmer.SetActive(true);
}
}
}


-  Next, Create PopupInfoWithFarmerController.cs file with script like this:

namespace MainScript {

using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using System;

public class PopupInfoWithFarmerController : MonoBehaviour
{
public string key;

public void UpLevelPlant()
{
Debug.Log(key);
}

public void UpLevelFarmer()
{
Debug.Log(key);
}

public void ClosePopup()
{
gameObject.SetActive(false);
}

public void SetKey(string tmpKey)
{
key = tmpKey;
}

void Start()
{
Debug.Log(key);
String keyData = "level_" + key;
if (PlayerPrefs.GetInt(keyData, 0) == 1)
{
}
}
}
}

- Next: Click Pannel, Change name to PopupInfoWithFarmer and untick check box at left. After, you must add Component Script and add PopupInfoWithFarmerController



- Next, you click your object as you want and add Component Box Collider and add Component Script ShowPopupInfoWithFarmerScript:


Well done! Hope it's help you show modal popup in unity game without button.

Rating: 10 (1 Votes)
Comment

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login