I have an interactable ground like a network of hexagon tiles in my project. I am using a new UI system from Unity, UI toolkit, and clicking a UI button makes Raycast go through and interact with the tile below.
I read about some dirty solutions, but I believe there is a better solution than these:
https://forum.unity.com/threads/ui-toolkit-and-raycast-block.1034938/#post-8218593
In old UI system was something like EventSystem.current.IsPointerOverGameObject
Can anyone help me?
Is the clicked button working? If not you are probably missing raycast target. Make sure it is set to true on your button's image. If that's not the case you could try using:
UnityEngine.Event.current.Use();
in your buttons callback to consume the event and stop further execution.
I found the way to make EventSystem.current.IsPointerOverGameObject work.
I had a big #Screen VisualElement streching the whole screen. In the UI builder there is a property named PickingMode under the first inspector section. You just set it to ignore and it will not be detected.
If you want to check individual elements, I have no solution for that, but there is a method .Pick(Vector2) and I don't know how it works yet.
https://docs.unity3d.com/Manual/UIE-faq-event-and-input-system.html
Related
I've got a UI menu in world space with camera flying around the canvases (representing the menu sections).
As for buttons I made some animations with separate animator for each button, so that I click "Single Player", for example, and the buttons in this canvas should be replaced (using animations) with other buttons that're outside the canvas and vice versa (when I hit "Back").
The thing is that I wanted to use List UIAnimators in the UIGameObject that holds all scripts to the scene. The problem is that Unity seems unable to receive Lists when I set the script to the button onClick thing. It doesn't show the methods with Lists at all. Is there a way to walk around it. So I can trigger several controllers in the same script, since I need to replace several buttons in the canvas using controllers of each one. Just looking for some tips, no coding needed, or maybe there are some references or tutorials. I'd really appreciate some help.
Menu layout, just to get a picture of the idea
Thanks in advance!
I am not entirely sure that I am following but if I understand correctly then you want to have a collection of different UI Elements and use the OnClick events from the Buttons to activate the corresponding animations for multiple elements at once.
Not sure if it is the best solution but you can make an array on the parent game object with all of your buttons with their animators and then with the OnClick event call a public function that plays the animation for the corresponding index
public void MyFunction(int index)
{
myUIElements[index].GetComponent<Animator>().Play();
}
Then just add multiple calls to that function with indices for all of the elements that you want to animate when that button is clicked as below:
Hi I have a quiz game my problem is when the user tap the three choices at the same time they will always have the right answer, i want to disable that, is it possible? Thanks you.
it depends if you need multitouch for something else, or else you should be able to just do
multiTouchEnabled = false; (https://docs.unity3d.com/ScriptReference/Input-multiTouchEnabled.html)
You could also in your code disable all input as soon as you register the first touch, so when just one of the buttons gets touched, turn off the collider on all the other buttons.
If this doesn't help we will need to see some code to be able to help.
I have button it possible create animate on click?
with photoshop i have created a two image (enabled and disabled). Insert the picturebox in Windows Forms and Click event..Click the image changes from enabled to disabled, but you can have an animation?
Like this:
It looks like you mentioned WinForms so I'll address that. Yes animation is possible but in general it's going to be a bit of work.
There appears to be an implementation of a general purpose animation framework (although limited) over on CodeProject. In the comments schallos posted a better implementation of the reflection code using expression trees.
The general principle is:
Use a PictureBox so you get double buffering
Use a timer control to control repainting (calling Invalidate() on your PictureBox)
You'll probably want to add some easing into the animation so it appears smoother; a bit of acceleration added to it when the user clicks goes a long way.
A timer is not required using a GIF.
Using windows forms you could start by creating an animated GIF for each button. It would have to include both the forward and backwards direction. You can do this through Photoshop via the "Animation" panel. On the PictureBox click event you can set the image to play or stop.
The code below would set your image on the beginning frame.
imgButtonDimension = new FrameDimension(imgButtonDimension.FrameDimensionsList[0]);
imgButton.SelectActiveFrame(imgButtonDimension, 0);
pictureBox.Image = imgButton;`
If this is the approach you'd like to take I can provide further elaboration.
I have for example a rectangle in a grid and I have a button "new" I want to make a new rectangle like the exist one and I want to make animation using c# to transfer the old rectangle to right out of View and transfer the new one from left to be on the show and I have a button back to reverse the animation and I want this animation everytime I press new and back how ?
I'm not exactly sure if this is what you are looking for. The way to go with Animations is to use Storyboards. MSDN has excellent code examples for this:
Check out: http://msdn.microsoft.com/en-us/library/ms742868.aspx
To execute your storyboard you can use Trigger. In your case would want to listen for Click events. An example can also be found in the link above (although they are using a different event).
I hope that helps you.
I am currently working on a Silverlight application using the Bing Map control, i am using a custom pushpin made up of an Image and a text block within a grid element, which works fine, this also allows me to have hover and right click events for each pushpin so all good so far, however there is a need for me to enable the user to drag the pushpin in any direction and have an a line connecting it to its actual position, sort of like an anchoring point.
I am struggling to see how to do this, I have seen lots of information on making the pushpins have the capability to be moved by the mouse but the line and anchor part is causing me a bit of a problem. Currently i keep my pushpins in various Observable Collections so that when they are updated the UI updates. If anyone has an Idea on a clean way of adding this functionality please let me know it will be much appreciated.
Many Thanks
I haven't got time to knock up a complete example. However I'll give away the basis of the solution. Replace the template with one based on a Canvas. For example you could have an ellipse to be the actual point on the map, a draggable border that has the ContentPresenter and a line to act as a tether.
The code needed is a) allow the Border to be dragged about and b) to move one end of the line about so that it lies under the Border.
I am still interested in other approaches but I have come up with a solution of paring my pushpin element with a MapPolyline, this in conjunction with the mouse handling to allow the user to drag the pushpin updates both, it is pretty effective and will do for now. I would still like to hear from anyone else with better suggestions though.