Say I want to make a brick dissapear when a certain dialog choice is selected.
I make an NPC, then I add a dialog tree. It is now set so when a player talks to the NPC, they have the choice to say "Can you make that brick dissapear?". The NPC replies "There you go!"
What would I need to do to make it so when the NPC replies, the brick dissapears?
On roblox?
There's an event in the Dialog object.
DialogChoiceSelected(Instance player, Instance dialogChoice)
This is how you can use it for making a brick "disappear" as long as you have defined the variables "Dialog" and "Brick"
Dialog.DialogChoiceSelected:connect(function(Player, Choice)
if Choice.Name == "BrickChanger" then
Brick.Transparency = 1
end
end)
The argument "Player" is the player who selected that choice, the "Choice" argument refers to the DialogChoice userdata that was chosen.
Related
my code is here ( https://www.codepile.net/pile/7mPpA9m0 ) the player is go out of box of canvans how to make it restrict
Just call the method setCollideWorldBounds on the players physics object, than the player should not be able to leave, teh Zone.
In the create function just add this line of code: this.player.body.setCollideWorldBounds(true);
Here is my code: (just so you know I am a beginner and I just started this week, though I do have knowledge with other languages and game engines)
func _on_Area2D_area_entered(area):
get_parent().get_node("Level 1/Area2D/Flag").rotation_degrees += 1
What I was trying to accomplish was that the Player GameObject would see if its in the area of the Flag, and if it is, the flag would rotate.
I am not sure where the issue is. I think it is probably in the second line. I provided a screenshot below if I did the setup wrong. I have looked at the other close questions asked on the same topic, but they did not answer my question.
The "Player" GameObject is the one with the script that contains the detection if its in the area2D.
If you want to check if the Area2D is positioned correctly during runtime enable Debug -> Visible Collision Shapes.
If you want to check if _on_Area2D_area_entered is running, add breakpoints (or use print).
Did you get an error?
If there isn't a Node there, this expression will cause an error in runtime:
get_parent().get_node("Level 1/Area2D/Flag")
If you want to be able to check, you can use get_node_or_null and is_instance_valid.
Since you didn't mention any error, I'm going to guess the method is not running.
If the method is not running, the most likely culprit is that - I'm guessing given then name of the method - you connected the "area_entered" signal but intended to connect the "body_entered" signal.
The "area_entered" signal will trigger when another Area2D enters the Area2D. But I only see one Area2D in your scene tree. On the other hand the "body_entered" will trigger when a PhysicsBody2D (e.g StaticBody2D, KinematicBody2D, RigidBody2D) enters the Area2D. In either case you get what entered as a parameter of the method.
Other reasons why the Area2D might not be detecting what you want include no intersection of collision_layer and collision_mask and monitoring being disabled.
And to dismiss a couple possible misconceptions:
The "area_entered" and "body_entered" trigger when the Area2D or PhysicsBody2D respectively enter the Area2D, not every frame they are inside. So rotation_degrees += 1 is not a rotation animation.
You will get notifications of anything that trigger the signals, not just the object to which you connected it. You may have to further filter, e.g. if body == self:.
For people arriving here from search, I want to link a similar case: Enemy is not affected by bullets. And also my full explanation of how to set up physic nodes.
So I have a part of my game where the character is selecting an area of the map. And it opening up a panel. I have made it so that happens but an=m now stuck on the other part of it. I want only certain area of the map to be intractable, so that I can bar the player from selecting areas of the map that they aren't ready for. I have no idea how to make game objects in the game uninteractable. I have looked on Stack overflow, Youtube an d the Unity API to no success. Can someone help me with that.
How to make things un-interactable will vary depending on your situation. I'll be presuming that you're map is broken up into a grid of sorts.
The basic setup would involve a bool, probably called 'CanAccessZone'.
Then you'll need a class, to store any access info and popup logic, by popup logic I mean make the element either non-interactable or show a popup, with the shown popup being dependant on 'CanAccessZone'. This class can then be set up by your Map class when the level is loaded, or you could let the popup class grab the necessary values from the Map class.
If you're using Unity's UI buttons for the map pieces, then you could set interactable to false, until you want to let the player access the zone. If you want to display a popup informing the player that they can't access the zone, then your button will be interactable, but the click will delegate to your popup logic method.
It's a similiar principle if you're using gameobjects as buttons. You'd be using any of the OnMouse events to handle click events. https://docs.unity3d.com/ScriptReference/MonoBehaviour.html
Hopefully this'll lead you in the right direction.
i´m trying to made a couple screens like a menu or a pause, and in these screens i want to put some "other screens", for example in my menu i want a button options and then the app slides and shows another screen with options like music/volume, or like a castlevania/megaman game when the user pause the game, some options are displayed, change the inventory, buy an hability or something like that, in this case when we try to manage the inventory the screen change an shows the information about the current inventory, so my question is how is managed this on libgdx, because i know there is a screen class but is that the way to do it?, constantly change between screens or there's another way.
This is actually what you need scene2D.
scene2d is well equipped for laying out, drawing, and handling input for game menus, HUD overlays, tools, and other UIs. The scene2d.ui package provides many actors and other utilities specifically for building UIs.
Lets assume you know about Stage which you will need to add your Actors like(buttons,textfield,input) all you have to do is implement Table, part of scene2D that contains method such as setVisible.
Lets say for example this is your log-in HUD. Now you want to hide it when a button is clicked.
Table table = new Table();
table.add(textField);
table.add(logInButton);
stage.addActor(table);
if(hideButton.isChecked())
{
table.setvisible(false)
}
else
{
table.setVisible(true)
}
This will hide all your Actors that contains in your table.
I have to add Joystick control in my Game
I had done with Two Approaches both works well for me , but confused Which one to go with.
1) Initiating Joystick Control from Players Object/Script and getting inputs there.
2) Add Joystick Control Directly to Game Scene and then accessing it in player script by findObjectwithTag and getting inputs .
Calling "Instantiate" and "GameObject.Find" is pretty expensive so in my opinion the efficient way is
1: Add Joystick Control Directly to Game Scene
2: Create a public object inside player and assign "joystick control" from inspector (Editor).