How to get mouse inputs in Rider's Console to do a Minesweeper - c#

I'm trying to do a Minesweeper in C# using the Rider's Console. At this time, I get the inputs by asking the player to enter coordinates using Console.ReadLine but I want to go to the next level and wait for the player to click on a cell of the board with the mouse.
But how to get mouse inputs, how to get different inputs whether the left or the right click is pressed and most importantly, how to know the coordinates of where the player clicked?

Related

Button Function Unavaiable in Unity

I made some edit to Snake&Ladder game where a question pop-up when player reach head of snake or bottom of the ladder. I manage to get the pop-up question appear but I can't find the function, not even the able to search the function.
I put the button code under transform position code when the player move after reach head of snake or bottom of the ladder.
Am I not allowed to separate button code from other button code in Unity?
How to make a button invalid or hide when the program runs to a certain step.
method 1:
Command1.Enabled = False button command is disabled.
Command1.Visible = False button command hidden.
Method 2:
//disable
this.GetComponent().enabled= false;
//disable and gray
this.GetComponent().interactable = false;
Hope it helps you.

What ist the difference between ontouchend and ontouchleave?

It seems like for the following question Google should give an answer but (for me) it doesn't.
What ist the difference between the events ontouchend and ontouchleave or ontouchstart and ontouchenter, respectively?
Many thanks
Philipp
you have to consider your widget as a collision box that react to touch on screen
ontouchend() is called when you lift off you finger off the screen, won't activate if you first slide ouside the colision box.
ontouchleave() is called if your finger touche the colision box werever it come from et leave eitheir by lift up or sliding your finger out of the colision box.
ontouchenter() is as soon your finger enter the colision box
ontouchstart() is only called is your finger directly touched the collision box, its make to avoid accidental activation by sliding from another place of the screen

Unity 2D - Detect Tiles with Mouse

Overview: I am making a 2D Tower Defense game with using Tilemaps as the environment and sprites as the towers and enemies. The mouse needs
Problem: I want to trigger different events/methods depending on which tile or sprite the mouse is hovering or clicking on.
Example - Hovering over buildable tiles shows a highlighted tile, but the highlight disappears when the mouse is over a "dead" un-buildable tile.
After 10+ hours of research, I think I need to use Raycasts, 2D Colliders, and Layers to detect when the mouse hovers over or clicks on a tile/object, but I don't know how to trigger different events/methods depending on which specific layer or tag the mouse is interacting with.
Question: How do I detect and access a tile or gameobject with a mouse hover/click? and is there a way to trigger different methods depending on tags/layers I assign to the things I want to detect on hover/click?
First of all you don't need raycasts or colliders to detect mouse events. There are many ways to do this, but you can create eventListener for use on multiple objects. Also as a simple solution you can consider using scripts(includes UnityEventListeners) attached to the objects you want to control.

Unity drag and drop check right or left (2D)

I wanna build a card game in Unity.
I want to player swipe cards left or right but I wanna show some tricks about what's gonna happen if they swipe left or right so if they grab the card (2D Image) and go a bit left or right a text will appear on image depends on side.
I tried to use swipe and use X axis change but It's not working properly.
Here is a basic pictured information about what i wanna build:
I would advise using the drag handlers system in unity to track where the card started, and trigger different effects at different distances / directions from its origin.
You can detect the drag of the card by implementing IBeginDragHandler, IDragHandler, IEndDragHandler on a script on your card object.
Begin is called when the object starts dragging, Drag is called during each frame its moving, and End is called when the object is dropped.
When a drag begins, you can cache the position where the card started. Then in Drag handler each frame you can check the distance of your card from where it started. Once it has moved more than a certain distance, you can trigger whatever tricks or effects you want to show.
Depending on how your coordinate space is set up, you could for example know left from right during drag updates such as:
// Inside of your on drag method, check each frame for where the card is
// If it has moved far enough, trigger an effect
if (Vector3.Distance(dragStartPosition, transfom.position) > yourTriggerDistance) {
// if X is greater, the card moved right
if (transform.position.x > dragStartPosition.x) {
// Trigger Right swipe text
ShowSomeRightSwipeText();
}
// otherwise, X is smaller, so the card has moved left by the required distance
else {
// Trigger left swipe text
ShowSomeLeftSwipeText();
}
}
Also please remember that:
In order for these interfaces to work, you need to have a Physics 2D Raycaster attached to your camera in the scene.
You need to make sure you have an Event System in the scene as well.
The above two things are often asked issues here regarding detecting object dragging.

Interacting with objects in SteamVR

I'm trying to get Interaction setup in my scene for a colour memory puzzle game in Unity.
I've managed to get the scene changing when the player interacts with a button on a Canvas, so I'm trying to somehow replicate that through a puzzle.
The player can trigger the colour randomizer to display random colours (out of 4), then the player will need to 'press' the buttons on the panel in the correct order to proceed.
So far, I have a canvas overlapping the buttons so the player can interact with them. Each button has a box collider over the button element, so when the mouse is clicked or the trigger button is pressed on the Oculus controller, it should register a button press. But as soon as the hand comes into contact with the 'collider box' the following NullReferenceException Shows;
NullReferenceException: Object reference not set to an instance of an object.
Valve.VR.SteamVR_Action_Boolean_Source.UpdateValue()
I'm trying to figure out a way to reference each 'box' in code to that it knows its that specific colour being pressed. The code is there to accept keyboard input, just having trouble with the VR element.

Categories