Hi, I'm making 2D game and have a question regarding the Event Editor. I currently have a few GameObjects with a certain script attached, which I've turned into prefabs and placed in each scene. I was wondering if there's a way to simplify this process. Should I use the Event Editor's Scene: Begin Game **and then use **Object: Call event to trigger the script?
If so, would I need to modify the script to work with Object: Call event, or is there a better method than using this approach?
Here is a script I’m working with, which are attached to GameObjects in each scene.
For more context, here’s the link https://adventurecreator.org/forum/discussion/15335/temporary-hide-inventory-item-icon-cursor#latest
using UnityEngine;
using AC;
public class AutoHideInventoryIcon : MonoBehaviour
{
void Update()
{
// Get the Menu by its name
AC.Menu menu = PlayerMenus.GetMenuWithName("a_Inventory");
// Check if the menu is visible
if (menu != null && menu.IsVisible())
{
// Get the specific MenuElement (btnUse) within the Menu
MenuElement button = menu.GetElementWithName("btnUse");
// Check if the mouse is over the button
bool hideInventoryIcon = KickStarter.playerMenus.MouseOverMenuElement == button && menu.IsOn();
// Adjust the cursor handling based on whether the button is being hovered over
KickStarter.cursorManager.inventoryHandling = hideInventoryIcon ? InventoryHandling.DoNothing : InventoryHandling.ChangeCursor;
}
else
{
// If the menu is not visible, ensure the inventory icon is shown if an item is selected
if (KickStarter.runtimeInventory.SelectedItem != null)
{
KickStarter.cursorManager.inventoryHandling = InventoryHandling.ChangeCursor;
}
}
}
}
Thank you again for all your help.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Using the Events Editor's Scene: Begin game event is the way to go, yes.
As the script has an Update loop, however, it'll need to be in the scene to run. To do this, have the event run an Object: Add or remove Action to spawn it in when the game begins.
You then just need to attach the Survive Scene Changes component to the prefab, to ensure it remains present after changing scene.
Thank you so much! I'm always amazed by how many features AC has. This will save me a lot of hassle. Thanks again!