Getting Unity 2D Perspective Camera + World Space Canvas Image sorting to work - unity3d

These are my current settings and let me know if you all need more information to help me solve this issue.
Camera : Perspective
Canvas Render Mode : World Space
In the picture below the focus here is when the user wants to select a ship of their choice they click where "Select V" is and you see "Fighter ship image, but the problem here is that not only is the "Green Circle" in the way but the dropdown itself it just not big enough.
In this second picture below you can see the scaling has been done to make the dropdown more visable but as you can see in this picture below that it is hidden behind another ship select box (ship2 in the Hierarchy).
I have tried making the Z coordinate larger/small and even if I have it come closer to the camera it still is represented behind the ship2 gameobject. I am at a total loss for ideas on how to approach this and if anyone could shed some light on this that would be awesome!
Here are 2 more screen shots just in-case the first 2 images were not enough information to go on.

If I understood your question correctly, your UI is behind the ship but you want it to be above the ship. If that's the case read below, else leave a comment.
objects in the hierarchy is rendered based on the order of your objects in the hierarchy, not the depth. The Unity UI is rendered from top to button in the hierarchy. Don**'t go changing the z-axis if you want to change the display order. It doesn't work like **NGUI.
If you want any object to be displayed on top, it has to be put bellow the object in the hierarchy NOT on top.
If object A is on top of object B in the scene, the problem is from the hierarchy. Go to the hierarchy and put object B below object A if you want object B to be on top of object A.
Also, don't scale the UI the way you did in picture #2. Change the scale of shipRow1 back to 1,1,1 then use the Width and the Height properties to change its size.

Related

Unity UI screen size issue

I'm quite new to Unity, so I'm sorry if this is a basic question. I've been trying to set up the UI for a mobile game, but I'm not quite sure how to make the UI lock it's position, no matter the screen size. I've tried using anchors (though I don't fully understand how to use them properly), I've tried using a canvas scaler, I've looked at the Unity document and I just can't seem to find an answer. The buttons are off screen/half off the screen when I build the game to my device/switch screen sizes in the game view. Does anyone know how to fix this?
You can set your anchor point by selecting the UI object (such as a button) and then clicking here and selecting the right anchor point. You can also press down shift to set the pivot and/or alt to move the object to that point at the same time. The object should now be anchored to that point and keep its position even if the resolution is changed. You can set a precise position from the inspector, too. Simply adjust the Pos X and Pos Y variables. It will still adhere to the anchor point.
Note that you might have to play around with the Canvas object's UI Scale mode and its settings to get the right setup.

While adding a canvas and then text into a gameobject, Canvas and text size problem

I am working on a 2d project with unity engine. (I am a newbie)
As you can see in image I already have a canvas for UI elements but also I have gameobjects under player element. I want to add text inside "govde" element. but when I add it;
at left bottom you can see my game. but canvas and text size is HUGE.
I dont know what is wrong with my game or canvas but I could not solve this.
By the way my gun works well so there are no errors in game. here is a photo of game scene;
Thank you for any kind of help. Have a nice day:)
EDIT : I Wanted to show the text box I wanted; please consider the numbers are so small. What I am asking is when width:2 and height:1 ok my textbox fits inside that car but since it is so small, i cannot show even 1 characters inside text box even if I make font size : 1. My english is not perfect sorry if I make any mistake. Here is picture;
and IF I Make bigger to everything, They don't fit to my game screen. I tried to move camera to far away but that did not changed to my Game Screen.
LASTLY: When I add my a text inside my UI CANVAS, it perfectly fits. But when I add same textbox to game object called Player as I needed, it is TOO BIG
SOLUTION : For anybody who deals with same problem try to create a text object inside a UI CANVAS, after that create another canvas inside game object. And lastly, drag textbox into second canvas . That solved all my problems. My second canvas is still huge and when I make it smaller my textbox gets smaller and smaller so I cannot use it again but I let canvas to be huge, no problem for me at all. Thanks for helps.
The text you created is the tiny black ‘New Text’ above the word basla. The canvas isn't actually viewable, you can add a ‘Panel’ underneath to confirm its size.
edit set font size and change width and height of text
keep scale at 1,1,1, track all the parent scale of each parent object, they do multiply in scale as you go down, so if one parent has scale 2,2,2 and its parent has scale 3,3,3 by the time you get to the text at 1,1,1 its scaled to 6,6,6 so keep this in mind and reorganize you hierarchy as needed

Unity: Positioning an element on canvas

I need to move an image down through canvas so that its central point would be where is now its top edge. It makes some 50 points, but if I decrease y by 50, it moves to different part of the screen on devices with different screen size. I guess, it's because my main canvas is set to scale with the screen size. So I suppose I need to manually divide the number 50 by my screen height and then code to multiply by Screen.height? Isn't there a more convenient way to move UI objects?
Allow me a second question: Do you think it is even wise to make a game purely on canvas? My game is simple 2D, only slightly animated and contains many layout elements, so I decided to go for it, but I have hard time to grasp the UI position rules.
you may have the problem of the anchoring.
Unity UI totally depends on the Anchoring, if you have got right anchoring there is no issue.
For example. if you anchored something at the Center than changing left and right value moves them according to the center anchor.
for clear visualization, you can paste a screenshot of the behavior.

NGUI can't bring sprite to front in Unity

I have a sprite widget in NGUI, and It can't be brought to front what ever the depth I change in the editor:
Note that the orange panel is a scroll view of NGUI.
Here is the inspector setting of the sprite that I want to set to the very front:
And here is the inspector setting that has overlapped the above sprite that I want to make front of it.
And here is the BottomPanel setting
I finally solve this problem by
Add another panel
Setting the added panel in front the origin one
Make the sprite child of the newly added panel
And the final hierarchy is like this:
And this link of NGUI forum helps
quoted here:
"Depth" property is used to determine the drawing order of the widgets within the same panel that use the same atlas. If you are using different atlases or labels using a dynamic font, bring the widgets forward on the transform's Z, moving them closer to the camera (-Z). If you are using different panels, adjust the transform of the panel you want to bring in front to a lower negative Z value (-Z). I highly recommend sticking to one atlas if you can manage it, it will make your life significantly easier.
And I make a youtube video to explain what I have achieved so far.
Everything looks fine to me but it doesn't seem to work for you. There is another workaround.
On the UIPanel, change the Render Q to Explicit then use z-axis to sort your UISprite. I mean the z position (P) not (R) or (S)
For example, change the z-axis of the "Sprite (1)" object to be 2 then change the z-axis of the "background" object to 1. If this does not work, change the values around.
Please make sure that the Sprite is under the panel.

In gamesalad actor moves out of the screen on x-axis

In gamesalad framework I am creating a game in which I have an actor which only moves on x-axis on touch is pressed. But when I move it to x-axis the actor goes away out of the range of the screen. Let me clarify that I am new to gamesalad framework.
plz help to solve the problem.
I'm reading this in two different ways:
1 - when you press your touch controls the actor disappears from the screen
2 - when you press the touch control the actor moves along the x-axis and out of the screen
For the sake of argument I'm going to assume that we're talking about number two.
What you'll need to do is restrict the actors movement to the boundaries of the current screen. You can do this is two ways with Gamesalad
1 - create an invisible barrier for your actor to collide against
2 - use a behaviour to prevent your actor from going beyond the screen boundary
I'll explain both:
1, Invisible barriers
What you'll do is create a new actor, and set it to collide with the actor that your controlling. You'll create a few instances of this actor to create a walled area for your actor. Although this works, it's a little cludgy and using additional actors in a scene take a little performance away from your application.
2, using a behaviour
In my opinion the better way is to use the given behaviours in Gamesalad itself.
To stop the player actor from moving off screen you can use a combination of Rules and the Constrain Attribute behaviour to achieve this.
The first thing to know is your screen size; for an iPad I believe it's 1074 along the x-axis.
So to stop the actor moving off either side of the screen you'll need to do the following:
Open up the player actor
the click on the "Create Rule" button on the top right.
A new rule window will appear, but default the first dropdown will say "Actor receives event" change this to "Attribute".
Next select the attribute to use the rule against, since we're interested in the x-axis we'll want to query that player attribute which will be:
(also known as self) > Position > X
Select the greater than symbol (">") and then enter the maximum width of the screen minus whatever border value you want, so I'll use 1014 (1024 - 10).
Find and drag the Constrain Attribute behaviour into your rule a set the actors X position to 1014.
This will stop the actor from going beyond one side of the screen, now copy the rule and amend the settings to that if the actor goes less than, say 10, it will constrain the actors X position to 10.
I'd post an image, but alas my Karma isn't large enough right now! Hence the large explanation!
Hope this is what you're looking for!
It is way easier than that.
In top of the Gamesalad Creator there is a play button, which you probably know, displays your progress. To the left of this button there is a button that looks like a little video camera, it changes the camera settings. So what you first have to do is click the camera button, then the rectangular camera screen will show itself as marked. In the center of each of the sides of the highlighted rectangular which is the camera screen, sits 1 little grey rectangular. Each of these needs to be pulled to the center of the camera view so that you get a little grey "cross" in the center and from the center to the boarder there will now be this highlighted color.
Second and last step is easy, just go under your character and in (type or drag in a behavior block) you type control camera... or drag the control camera block, which as by the type box is statet possible.
Since Gamesalad only can have one camera at a time, and you character is the only one with the control camera option applied it will follow him and only him. Wherever your character starts on the screen, the camera will follow it when it passes through the center of the screen. You may know this from Super Mario Bros. Where you start of a little to the left and walk right and the second Mario enters the center of the screen, the camera follows him from then on.
Hope this helps... :