How can I put a UI Image always on top in Unity 3D - unity3d

I have noticed that in a canvas the elements are drawn from top to bottom so the image above is covered by the image below. The problem is that I want an ui image that is not the last sibling of the canvas to stay on top of all the others. How can I do?

I think you can try two ways.
First.
Use Transform.SetAsFirstSibling() to put the UI Component on top
Second.
Use CanvasGroup.sortingOrder to help your UI Component grouping.
Ref
http://docs.unity3d.com/Manual/class-CanvasGroup.html
http://docs.unity3d.com/ScriptReference/Transform.html

there are couple of functions you can use for setting orders
Transform.SetAsFirstSibling
Transform.SetAsLastSibling
Transform.SetSiblingIndex

Related

Unity problem with ordering and sorting layers

I've some problems with Unity layers. Before was everything ok, now, I don't know why the game view show some elements behind. Has you can see in the image the red background in the game view isn't visible even if it has the same sorting layer has the text and its order in layer is fewer.
So, it would be helpfull if you would also share screenshots of the components you use, like SpriteRenderer...
Also, also, maybe show the layers you have configured.
Here is one setup for example:
You can configure which sorting layers you want and in what order
After that in your Render Component of Choice you can set this layer and use the number (order in layer) for finer sorting
Finally I solved removing the sprite renderer for the background of the parent of the texts and I putted a separated sprite square for all the background with a order fewer

Scale UI buttons and images with screen size

I ma developing a game for unity and i want to be able to scale my buttons and UI elements to fit different screen sizes. Please how can i go about this? I have tried scale with screen size and it doesn't seem to help me. Is there a script i can use for this?
You will want to use a canvas scaler for this.
You simply attach this object to your canvas parenting your UI elements and it will scale them acordingly.
You will also want to make sure your UI elements are anchored correctly so that they stretch with their correct anchor point.

how to create dynamic UI that adjust itself to current screen dimensions after loading?

I have created a level editor using new UI system in Unity3D.
Using Level Editor:
I can drag the ui elements,
I am able to save them in scriptable objects
But how could i save and load them at runtime?
I mean, if i create a level with some {width x hight} resolution and if i load it on different resolution, then the whole UI positioning get distorted.
How could i anchor them correctly programmatically?
Any help would be appreciated.
There are good video tutorials about the 4.6.x UI here:
http://unity3d.com/learn/tutorials/modules/beginner/ui.
Especially for positioning the elements I recommend watching: http://unity3d.com/learn/tutorials/modules/beginner/ui/rect-transform.
I suggest you learn how to use the anchor correctly first. If you want to change the position and size of UI element in a script you can do that through the RectTransform component. It offers functions like offsetMax,offsetMin and sizeDelta for position your UI element. The functions you need to use depend on your anchor setting.
as LokiSinclair said. You just need to Adjust the Scale that the new UI provided. It is the four Arrow on the Canvas of each Object and every UI object is inheriting their scale behavior from their Parent.

iPhone hide portion of image in UIScrollView

I am brand new to iPhone app development. I am trying to create an image reader using UIScrollView. I need to focus a portion of an image and hide the rest. Till now I am only able to focus required part of an image but have no clue how to hide the rest. I had a suggestion that, I need to add four views at top, bottom, left and right. I need to hide those as per requirement. But, I was able to go no where with the suggestion. Can you please tell me how can I implement the functionality?
I don't understand what you really want to do. But if you think putting for views above I might suggest you use mask image for the same. Use alpha component.
Atlast I was successful in hiding part of an image. I used four views with background color and resized them according to the portion I need to display.

Dragging images from a scrollable region in Raphael?

I'm investigating the feasibility of using Raphael for a user-research project. One of the features allows for users to drag images onto a canvas and we record where they placed it. The pool of images is potentially quite large and we'll have them in a scrollable box in the tool.
I put together a quick wireframe of the issue I'm looking into since it'll probably be clearer than my explanation.
Please see the wireframe:
I'd stick with straight HTML/CSS and use jQueryUI draggables, as you mention in your comment.
You don't appear to need any of the drawing/display features SVG offers, yet if you went that route, you'd have to build your own custom scrolling behavior (instead of setting a CSS overflow-y rule) and picture layout algorithms (again instead of using CSS floats or something).
You can create a scrollable region using Raphael.
Create the viewport with fixed
dimensions (say 800x600)
Draw the images with increasing y value. After few images, the y value will go beyond 600. It will be drawn but will not be visible in the viewport.
Create a scrollbar using raphael rects. Attach drag events to the scrollbar handle rect.
When the handle is moved, translate all the images accordingly.
For e.g. lets assume in step 2, you had drawn all the images and the bottom most point of the end image is having y value 2000. Assuming the scrollbar has length 500, each dx movement of the handle will have to translate 2000/500 = 4dx. You can calculate the handle length similarly using ratios.
Since everything inside a single Raphael paper the dragging of images will work seamlessly. You will have to maintain the positions of each images.
You might find this demo similar
Remember you can always use getBBox when you drop. In this case it's rects but images would be the same..
http://irunmywebsite.com/raphael/additionalhelp.php?q=bearbones