I have a scroll view and when I place buttons inside it they are not interactable how I can fix that?
I'm listing down common mistakes which can cause UI intractable issues in Unity:
Make sure you have a Game Object with an Event System and Standalone Input Module component attached to it in your Scene, You can create one from GameObject Menu > UI > Event System.
Screenshot showing the same
Make sure some UI element/Game Object not blocking your clicks(sometimes it happens we have a transparent image over our element which can block input).
Make sure there is a Graphics Raycaster component attached to the game object which contains a Canvas component if you want their child elements to receive input.
Make sure your button's Interactable property is set to true.
Make sure you set the Raycast Target property to true for your button's Image.
Is it in the contents box inside the scroll View? If not then put the game object in there
Related
i want to make an area in my game where i can get touch inputs from the player.
Now i get touch from all the way of the screen.
strong textI want to get from the buttom of the screen or so.
You can make an invisible UI element or GameObject and on there check if it was clicked or not. You can do this with either https://docs.unity3d.com/2018.1/Documentation/ScriptReference/EventSystems.IPointerClickHandler.html or https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseDown.html
I am entirely new to Unity. I have a task to work with a tool in Unity. I'm not sure the "Game" is where I should work or the "Scene"? this is how my "Game" tab looks like, but I saw animations in the "Scene" tab. for changing parameters of animation, I should come back to the "Game" tab to change and again go to the "Scene" tab to see the result. I think something is wrong, and I should see the animation in the "Game" tab. Am I right?
It was confusing for me to explain my problem cause I have no idea!
It's very confusing what is happening in your Unity scene.
I assume either you have a disabled camera object or no camera at all.
Search the hierarchy for a MainCamera object and enable it. The game view is rendered from cameras in the application. If you cannot find a camera gameobject, try adding a camera (Gameobject>Camera). If you could find a camera gameobject, you should also check it's Camera component has target display set to Display 1.
In the Scene View at the top left, you can click 2D View. Then you can select the canvas in the hierarchy and press "F", while your mouse is over the scene view, to focus it there. In the end, you should be able to see the canvas in the scene view just as you can in the game view.
In fact, you don't need a camera in the scene to render UI elements, which is quite confusing. So if you don't need to solve the "no camera rendering" problem, as long as there are no 3D objects you want to draw. Keep in mind that you will probably need to manually place an audio listener if you want to hear something at some point.
In your hierarchy window search box write this :
t:Camera
And see if any will show up. The camera needs to be enabled if there is one present. If there is none, then you need to create one from GameObjects -> Camera.
As above answers indicate, there is a missing Camera object. Please keep in mind also that a disabled parent object will affect child objects. This was my case, my Camera object was a child object for a XR Ring object which was disabled and I was getting the "No Cameras rendering" message.
I am using an Event Trigger component on a UI Button in unity, with the Pointer Enter function that runs when the mouse pointer hovers over the button. However, I have noticed that this function also runs when I hover over what the colliders of the children would be, even though there are no box colliders on the child objects. What is going on here?
It's like it is using compound colliders even though I only have a box collider 2D on the parent object, and it is UI.
I am using C#.
As far as I know for UI you don't need any collider at all.
Rather any UI element (on this or child objects) like Text, Image, etc which has RaycastTarget enabled receive the events which will then bubble up until any of the parent object consumes them.
And the parent of it is just a prefab.
This is the parent prefab screenshot :
Canvas are game objects that usually can't be moved, one reason to move one is because you want it in World Space instead of Screen Space.
Canvas is the container of all of your UI, what you probably want is to move an image, a text, or any other type of UI component, those components must be children of the Canvas and they will be able to move.
You can also have an empty child containing more game objects and that one will be able to move.
Please read more about Unity's UI and Canvas.
I am new to unity and working on a image viewer in unity2D.
I am not sure if I choose components true but for now working fine.
most of the project is script based
I created a prefab which has a raw image
and in script I Instantiate prefabs in a scrollviews content
images are displayed no problem in that
I added some events where I Instantiate my prefab pointerDown, beginDrag, endDrag
dragging workin fine too
but when I drag any added prefab to older added prefab it stays on top but if I drag it to a newer added prefabs it stays under them.
I think its because the hierarchy order.
how can I change the order or how can I manage to make prefab stay on top when dragging
ps: on the image thumb_0 is added first and after drag it stays on behind thumb_2
if you can access the Transform of your prefabs you can use the method SetAsLastSibling(); it will move your gameobject to the last spot under your parent object, therefore causing it to be drawn on top
https://docs.unity3d.com/ScriptReference/Transform.SetAsLastSibling.html
EDIT :unless you mean dragging it manually, so then drag it to the bottom , last item always appears on top