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:
Related
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
I have developed a board game. I want to add one more feature onto it. If I move my cursor onto one of the entry on the game board. It will show relevant information right next to the cursor. I know I can add invisible controls onto the game board and use Control.MouseHover Event to make this feature work. However, what kind of invisible control I can add onto the board? The rectangle shape will be most useful. One more question, how to display text right next to the cursor? I have attached the board I was talking about in below.
Thank you for helping me.
I am making the game of minesweeper and I wrote the game all on the gui in c#. I want to now work on the model-view aspect of things and I need help bringing the gui together with the model.
Meaning:
I made a call called MinesweeperModel which in it will contain a 10 x 10 grid[,] of values. If the grid has a bomb the value will be -1 if not it will be 0. In the model view all of the methods are written there, like NewGame(), GameOver(), SetUp(), GameLogicChecker()(this checks if there are any bombs and assigns the square a value to how many bombs it is near) etc. However in the gui aspect of things I have a similar grid of buttons[,] which are also 10X10. What I am trying to do is when I click on a button that coordinate will correspond to a coordinate in the model grid, and therefore the method created in the model grid can work on the buttons as well. But I am not exactly sure how to bring it together.
Thanks!
You could go through and add button click events to each button by double clicking it in the gui editor. Then having it call the GameLogicChecker() function inside of it. Maybe you could give a little bit more information I'm not quite sure what your asking for.
I try to explain my problem:
I got many customcontrols of same type on a panel.
At runtime I'm free to move any custumcontrol ( mousedown and mousemove events) in the form with mouse over any others customcontrols using bringtofront() to have it over all.
Now I need to know when the control I'm moving is over any other control and which control is under.
So far I've tryed to use drag-n-drop events but without success, there's some other way to do this or I've to re elaborate it with drag events?
thank you all for help
and sorry for my English.
EDIT:
The controls are cards game and my final goal is to use cards to create logical sequence following rules based on card value and/or color.
You can't solve the problem with drag-and-drop because you're not actually dropping one control onto the other control. You're merely moving them around in the form.
You need to become familiar with Z order, which is the front-to-back arrangement of objects in a virtual 3D space. To adjust the Z order, you can call the BringToFront and SendToBack methods of any object that derives from System.Windows.Forms.Control.
The Z order is also exposed by the parent (container) control's Controls collection. Using the GetChildIndex method, you can determine the position of any control within the Z order.
So now, all you need to do is figure out which control the control you're dragging is over. Do that by comparing the Location properties of the two controls. When you know that the locations of two controls overlap, check their respective Z order indices to see which one is on top.
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.