0
\$\begingroup\$

In the editor i did:

GameObject > UI > Image

On the Canvas i changed the Render Mode to Screen Space - Camera.

It created a Canvas and a child Image in the Hierarchy. Then i changed the Image source to UISprite changed the color to red also added to it a material in red.

I can't changed the Canvas anchors not sure why.

The Image rect transform anchors is set to the center.

I don't have a Main Camera the only camera i have is on the FirstPersonController (The FirstPersonController is a child of a FPSController).

But still the red dot/circle is a bit to the left not in center.

Screenshot of the Canvas:

image001

And two screenshots of the Image:

image002

And

image003

\$\endgroup\$
1
\$\begingroup\$

OnGUI is deprecated. And it has been for a long time. Make sure your Unity is updated at least to a fairly recent version.

Use the Unity Canvas.

On the Unity Main Screen, go to GameObject in the menu bar at the top, scroll down to UI, and select image. It will automatically create a new Canvas for you (assuming you don't have one). It will also create a new image. Click on the Canvas, and set it's "Render Mode" to "Screen Space - Camera". Then set the Camera to your Main Camera/The Camera for your game.

By default, the anchor points of the image you created should be set to center, so simply set the x, and y transform to 0. Your image will be centered. If the anchor points are not automatically set to Center, simply click on the transform of the image, and at the top should be it's anchor point. Set it to center and follow the same steps listed in this paragraph.

Make the created image your crosshair circle/hit marker by selecting the sprite and setting it to whatever you need.

\$\endgroup\$
  • \$\begingroup\$ I did it all. The texture is still a bit to the left not in center. \$\endgroup\$ – user1196715 Nov 11 '17 at 6:09
  • \$\begingroup\$ Provide a link to show the Unity scene. \$\endgroup\$ – cmprogram Nov 11 '17 at 6:12
  • \$\begingroup\$ Ok i will update my question with what i did with a screenshots. \$\endgroup\$ – user1196715 Nov 11 '17 at 6:18
  • \$\begingroup\$ I found how to do it. \$\endgroup\$ – user1196715 Nov 11 '17 at 7:54
  • \$\begingroup\$ Upon reading your updated question, it is exactly as I had described. Please accept the answer for future users. \$\endgroup\$ – cmprogram Nov 11 '17 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.