How to scale objects with screen size in Unity - c#

For canvas item no problem, buttons or any other UI elements can be scaled with screensize. On the other hand, I can not do this for objects. I need a box in my design and in every screensize it should fit all screen.
I need this design.
But when I change screensize design does not remain same.
other image:
For button or canvas elements there is no problem I can do it by "scale with screen size" but when it comes to objects I can not do like this. How can I do?

It seems like a vignette would be useful rather than scaling a gameobject.
Quick explanation:
With Unity's post-processing properly added and a volume created, add the effect/override of vignette and change vignette's mode to mask. And add an image as a mask.
If not experienced with post-processing:
For unity 3d HDRP or URP(may work with unity 2d but probably not):
Add a global volume through the hierarchy by first navigating to the plus sign drop-down then to volume then click on global volume. If unavailable, add an empty object with a volume component. Create a profile then add the override of the vignette. Under vignette change the mode to mask and select an image you want the mask to be.
That should be all for unity HDRP or URP.
Without HDRP or URP:
Add the postprocessing package if not installed via the package manager.
Create an empty object and add post-processing volume. Checkmark is-global. Create a new post-processing profile. Add effect vignette. Checkmark 'Mode' and switch it to masked.
Checkmark and change 'Mask' to the image you want.
This should allow the image to pop up over the camera.
Extra note: Make Sure The Image Has A Transparent Background On The Vignette Mask Where You Want The Player To See Through
Please search for how to use post-processing package if any issues occur.

Related

How to put a picture exactly on the road?

I created Custom Pin in Xamarin.Forms.Maps and add my icon. How I can put my icon on the road and and move this icon along.My problem is not with getting accurate data, but with displaying the image itself exactly on the road. For example, if the road is horizontal, then the icon (car) should stand horizontally on the road
You could use Map Tracking. It would show the driver route and car position on the map. The car should move according to its current position in the route.
Install the Xamarin.Forms.GoogleMaps.
https://www.nuget.org/packages/Xamarin.Forms.GoogleMaps/
You could download the source file from the GitHub for reference.
https://github.com/WendyZang/MapTrackingSample

What is the correct method for showing a full screen photo within a mobile app using Unity?

I am creating a mobile app using Unity. I would like to place a photo which fills the screen and then place some 3D objects on top of this photo. The photo is created during runtime and is saved to the persistance data folder.
What is the best method to achieve this? The options I see are Raw Image/Image/Sprite. However, I have been unable to achieve the above mentioned goal using either of these component types.
What about making a panel on a canvas, setting the image as background and the canvas to fit screen size?
Then place the objects on front of it, manually or as children of said canvas but higher in the hierarchy.
I don't really understand what you intend to do, just trying to help.
editing my original answer: you need to use RawImage to be able to easily load images that are not marked as Sprite in the editor
You load images from file like this :
Texture2D texture = new Texture2D(1,1); // the following needs a non null starting poin
var path=System.IO.Path.Combine(Application.streamingAssetsPath,"your_file.jpg");
byte[] bytes=System.IO.File.ReadAllBytes(path);
texture.LoadImage(bytes);
rawImage.texture=texture;
As far as keeping it filling the screen the AspectRatioFiter component is likely to do the job
To get 3d objects rendering in front, set your canvas to 'Screen Space - Camera' and point it to your camera. This will behave similar to word space in regards to rendernig order (will get 3d sroted) but canvas size will match camera viewport, so AspectRatioFitter will be able to do its job

Why my Canvas is not on same positions as on my device?

I hope I am not too boring because again I have one dumb question.
I have made my game near till end but now I have one big problem. My images , text etc in my Canvas panel are not display correctly on all devices.
I made the game and it looks perfect on unity. Then I build the same game to my Galaxy S8 Device and i realized that some images are out of the screen in other words I can not see some images in corners or some text .. That means my canvas settings are not correct ..
This is my canvas settings.
When I change UI scale mode to constant pixel or constant physical size It doesn't show properly even in unity or on phone seems like he zoom in automaticlly too much. I made the best settings for UI SCALE MODE - > Scale with screen size, but on some devices it doesn't show up correctly ( it shows with little errors like corner text is not shown because it looks like he is outside of screen)
I hope someone has solution for this.
Here is my general settings of canvas, which i always use and never got any issue in positioning.
Also when you put any object, RectTransform's value(marked in following image) is not set properly then it will go outside of screen.
For more details see : https://docs.unity3d.com/Manual/class-RectTransform.html
Also you can check different screen ratio from unity and even add new to it and test.

How to setup a shopping based UI for different screen sizes in unity?

I am trying to set up a shopping based UI for different screen sizes.In the canvas settings inside the Inspector I have given a reference resolution of 750 x 1334(Iphone 6)
UI scale mode - Scale with screen size
Match(Width-Height) - 0.5 (Which I change to one can see them in the images)
Somehow I placed the Images and text according to given design.It looks ok in the Iphone resolution.But in Ipad the buttons and text gets mixed up.
Now I change the Match(Width-Height) - 1 .The result is it looks okay but in the ipad view it looks small and there is plenty of space along the two sides.
How to get a matching view/look for all the different screen sizes.
Images are given below
Actually, u don't need to change the match size.
what u actually have to use are anchors. If u use anchors no matter how the size of the screen changes the UI element will resize with it.
see this video from unity officials. It will definitely solve ur issue.
https://www.youtube.com/watch?v=FeheZqu85WI&list=PLX2vGYjWbI0Qp0sD8_RKgbWul7z_eyNAv&index=2
thank you.
U can accept this answer if this solves ur issue.

Taking screenshot of partial area in Unity?

My game lets you dress up your character. I would like to save off that image (but not the rest of the 800x600 screen) to a file. According to the help, I can use Application.CaptureScreen() to capture the full screen but how does one capture just one part of it?
If you want full control over what area you want to screenshot, I would recommend setting up a new camera with a RenderTexture. This will enable a more flexible way of controlling your composition for your screenshots. Like the Avatar Creator on Xbox360.
Create a new camera and align it to fit the image and composition of choice.
Add a RenderTexture
Use ReadPixels to read from the RenderTexture into a Texture2D and save using EncodeToPNG.
Save to disk or upload to server
http://docs.unity3d.com/Manual/class-RenderTexture.html
http://docs.unity3d.com/ScriptReference/Texture2D.EncodeToPNG.html

Categories

Resources