How do I check whether I have changed rooms in Game Maker Studio 2? - pause

So I have been working on a pause menu for a game I have been working on with Game Maker Studio 2.
Whenever I change rooms (like going to the options room or main menu) the pause menu stays and everything looks very weird and overlapped. Is there a way to check if I have changed rooms to destroy the objects the menu is made up of
(So like if (room has changed) {Delete pause menu})*
If someone could give me the correct syntax that would be awesome!
Thanks.
*I have sorted out deleting the menu, just need to know what to put in the if statement

For my game, I've done a check if the room is the same as the room in the main menu/options menu, or make a check that the pause menu only appear when it's not the main menu/options menu.
var roomname = room_get_name(room);
if (roomname != r_mainmenu && roomname != r_optionsmenu)
{
//draw pause menu
}
Another idea is to hide the pause menu once you go back to the main menu.

Related

How do you automatically focus on an inputfield when opening/activating the UI in Unity3d?

I am making a game where you must open or activate the UI with the space bar. Now, this works perfectly fine, but it is pretty annoying that every time you open the UI you must click on the inputfield to write in it. Is there any way around this? So is there a way to open or activate the UI without having to click on the field to be able to write in it?
I looked for YouTube videos and tried to find similar problems in other forums, but wasn't able to find a script, nor was I able to find some Unity settings to do so.
You could use e.g.
private class SelectOnEnable : MonoBehaviour
{
private void OnEnable()
{
EventSystem.current.SetSelectedGameObject(null);
EventSystem.current.SetSelectedGameObject(gameObject);
}
}
and attach it to whatever object that should become the selected one everytime it is enabled. See EventSystem.SetSelectedGameObject
Can't test it right now but it might still require the User to hit Enter in order to also actually set the Input field into edit mode. The upper line only sets it as selected UI element (similar to using TAB in a browser).
Otherwise I think you would go through
yourInputField.DeactivateInputField()
yourInputField.ActivateInputField();
to directly set it active. See InputField.ActivateInputField. Might have to do both in combination - again can't test right now ;)
Thank you very much, derHugo! Everything works like a charm now! You saved me a lot of time. Referring to your last comment, I used both of them, and it seems to work very well for me. Here is the code I used:
`private void OnEnable()
{
EventSystem.current.SetSelectedGameObject(gameObject);
GameManager.GetComponent().inputFieldInMainUi.ActivateInputField();
EventSystem.current.SetSelectedGameObject(null);
GameManager.GetComponent<InputFieldComparision>().inputFieldInMainUi.DeactivateInputField();
}`

How to change scene based on button click using Unity and MRTK?

I'm trying to implement a menu with some buttons in order to load different scenes based on the clicked button.
What I've tried
I created a total of 3 scenes : menu, main and secondary. The menu scene contains the buttons. On the first button I added Interactable, NearInteractionTouchable and LoadContentScene. I then selected the desired scene to load in LoadContentScene and added an OnClick event to the Interactable script which triggers LoadContentScene.LoadContent.
you can see it there
The problem
Now when I click on my button, the next scene isn't loading and I have those error messages in my Unity console :
Unable to find ISceneTransitionService service.
NullReferenceException: Object reference not set to an instance of an object
Microsoft.MixedReality.Toolkit.Extensions.SceneTransitions.LoadContentScene.LoadContent () ...
What did I do wrong ? I tried to find some solutions in the documentation or online but I couldn't find any tutorials
From the error message you are trying to use the Scene transition service, please check if this service is registered in MixedRealityToolkit->Extensions. To clarify, for scene loading, this service is not necessary, if you don't know what it does, you can disable the corresponding code.
Also, you can refer Scene system content loading - MRTK 2 | Microsoft Learn and this official sample - OpenXR-Unity-MixedReality-Samples/BasicSample at main · microsoft/OpenXR-Unity-MixedReality-Samples · GitHub.

No function dropdown in AnimationEvent in Unity

I try to handle some events during animations, but everywhere I look, every tutorial have access to AnimatorEvent Inspector like this:
A nice simple field, where you can select a function, I want this!
But instead of this, I always getting this sick 5 fields view, and don't have any idea how to handle animation event in this case!
I tried to create function test() with debug log, but it didn't work anyway. Why I can't get access to this simple window where I can choose an function?
You will need to add this animation into a State in Animator Controller (via Animator Window).
In the object which contains Animator component, attach your script component to it.
Open the Animation window, select the object above, you will see a dropdown of animations (top left) which Animator Controller of this object contains. Choose and add event to the animation you want to.
Select the event in Animation Window, in the Inspector, you should see the dropdown of public functions of your script component attached above.
Answer by Aluminium18
Sometimes it doesn't work even if you do all things according to tutorials or advices in internet. I often leave Unity editor launched for a long time without any interactions with it. After several gibernations and several days it can get buggy - various errors appear, you can't see some functions from scripts and so on. So, just reloading the Unity editor solves many of such issues for me. And it continues to happen so for several years no matter what Unity version you have. I tried versions from 2019.x.x to 2022.x.x - all this time Unity behaves itself the same.

How to create a menu in unity to purchase ammo for my weapons

I am a student currently creating a zombie FPS game using Unity 3D and I simply want to when I press 'E' on the keyboard, I want a menu to pop up and show the prices of the ammo (I have a pistol9mm and an AK) and when I click on buy, the ammo is purchased and I have more ammo.
Is there any helpful suggestions on how I will approach this scenario please ?
So first and most importantly, you have to create the Menu where you are going to buy the ammo from, make the buttons and then script them in a way that when you press them they take money away from the player and then gives him ammo. A single button "Buy ammo" is enough and just a little panel on which the button should stay is needed. After making the menu work, go to the script where you check if the player has pressed the "E" key. Create a new Game Object which holds the Menu where you buy the ammo from and when checking if the player has pressed the "E" key, check if the menu is opened. If it is not, then open the menu, if it is opened, close it. Here is a simple way of doing it.
public GameObject menu;
private bool isOpen = false;
void Update(){
if(Input.GetKeyDown("E")){ //When "E" key is pressed
if(isOpen == false){ //If the menu is closed, open it
isOpen = true;
menu.SetActive(true)
}else if(isOpen == true){ //If the menu is opened, close it
isOpen = false;
menu.SeyActive(false);
}
}
}
The way it works is, it either sets the menu to active or unactive when you press the "E" key and it's really simple too. Also when you are done with the Menu set it to active so it doesnt apear on the screen when starting the game, just so it will apear after pressing "E" and so players don't have to close it every time.
I hope i helped you, if you have any questions feel free to ask.

are there DOM events for controller presses on the PS3?

I want to develop a site which is easy to use from a Playstation 3 PS3 game console web browser. I thought it would be good to make screen actions on button presses on the console.
I can find no information on how to do this after quite a bit of searching.
Any info or links highly appreciated!
Why not write a function that displays a message for every "keystroke" and you'll see what values they represent:
$(document).keypress(function(event) {
alert(event.which);
});
Then you can use the number you get from this test and create some logic based on that.
Like this perhaps:
if(event.which == 13) {
// display cool menu maybe?
}
From what I've tested so far, the left stick generates mouse events, left pad with arrows generates keyboard events corresponding to arrows, while the right stick generates a mouseevent but unfortunately it does not move the mouse, but rather scrolls the window.
I do not know how to detect in which direction the stick is pushed (unless the cursor actually moved or the background scrolled, in which cases it is quite trivial).
Check: http://vanisoft.pl/~lopuszanski/public/ps3/