- Home /
Image overlay in center of screen
Hey guys, so I have an image that I use as an aiming icon in a first person game, and I want to put it exactly in the middle of the screen, so even when I adjust the screen size in game (on play) I want the image/icon to correctly adjust. Now what is the most efficient way to achieve this? Now with Unity's new UI system I'm a bit lost :p thanks for your help!!
I do have a setup that works atm, but I just messed around and I didn't really know what I was doing :p so thats why I need an answer :) I wanna do it properly
Answer by Addyarb · Apr 25, 2015 at 08:24 PM
Create new Canvas
Create new Image
Attach sprite to image component
That's pretty much it. Do some research on the anchors feature in uGUI. By default, your image will stay in the middle of the screen relative to the resolution. Just be sure to put it in the middle of the screen to begin with (it starts there by default once you create it though).
Cool, it worked, and anyway that you know that I can toggle the image on and off in a script?
Yes, like with a bool?
public GameObject CrossHair; //drag your GameObject into here.
public bool visible; //a bool to set our crosshair on or off.
void Update()
{
if(visible)
CrossHair.setActive(true);
else
CrossHair.setActive(false);
}
Also, be sure to mark my answer as correct by clicking the button under the thumbs-down button to the left of my answer. Thanks!
Answer by AliceScott · Jan 06, 2018 at 12:03 AM
Simple….!
If you set new color to the Image (like in posts before) then you lose the highlight color, etc. I am learning developing course and I am trying many time to resolve this but I don't do this. Now I am working on Assignment Writing Service Website.
Your answer
Follow this Question
Related Questions
How can I get a UI Panel's size in relation to the screen size? 1 Answer
Unity 5.0 Trying to Change the Image - Source Image via Script 3 Answers
Unity 3d C# GUI box goes off to the side needs to be in the center of the screen 0 Answers
Rendering GUI.Buttons in the middle of the screen 5 Answers
How Do I Center A GUI Label? 5 Answers