69 lines
1.9 KiB
C#
69 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class MainStore2 : MonoBehaviour{
|
|
public GameObject ButtonToToggleMenu;
|
|
public GameObject MenuToToggle;
|
|
// public GameObject OutsideMenuArea;
|
|
|
|
Button button;
|
|
// Button OutsideMenu_button;
|
|
public GameObject[] OutsideMenu_gameObjects; // Array to hold the list of GameObjects
|
|
|
|
|
|
void OnEnable(){
|
|
MenuToToggle.SetActive(false);
|
|
|
|
// Get the Button component from the GameObject
|
|
button = ButtonToToggleMenu.GetComponent<Button>();
|
|
// OutsideMenu_button = OutsideMenuArea.GetComponent<Button>();
|
|
|
|
}
|
|
|
|
|
|
// This method is called when the button is clicked
|
|
public void ToggleObject(){
|
|
Debug.Log("YK");
|
|
// Check if the objectToToggle is active
|
|
bool isActive = MenuToToggle.activeSelf;
|
|
Debug.Log(isActive);
|
|
|
|
// Toggle the active state of the object
|
|
MenuToToggle.SetActive(!isActive);
|
|
}
|
|
|
|
public void CloseMenu(){
|
|
MenuToToggle.SetActive(false);
|
|
}
|
|
|
|
|
|
// Start is called before the first frame update
|
|
void Start(){
|
|
// Add an onClick listener to the button
|
|
button.onClick.AddListener(ToggleObject);
|
|
|
|
|
|
|
|
// Loop through each GameObject in the array
|
|
foreach (GameObject obj in OutsideMenu_gameObjects){
|
|
// Add a pointer click listener to each GameObject
|
|
EventTrigger trigger = obj.GetComponent<EventTrigger>();
|
|
if (trigger == null){
|
|
trigger = obj.AddComponent<EventTrigger>();
|
|
}
|
|
EventTrigger.Entry entry = new EventTrigger.Entry { eventID = EventTriggerType.PointerClick };
|
|
entry.callback.AddListener((data) => CloseMenu());
|
|
trigger.triggers.Add(entry);
|
|
}
|
|
}
|
|
|
|
|
|
// Update is called once per frame
|
|
void Update(){
|
|
|
|
}
|
|
}
|