I’ve been searching around for an FPS crosshair tutorial that doesn’t move around at all, and either there doesn’t seem to be one that works, or people all have completely different ideas. All I need for this FPS is a crosshair that stays in the center of the screen no matter where you look or walk…like how the one in Portal behaves.
[30274-screen+shot+2014-08-02+at+2.56.12+pm.png|30274]
I’ve attempted to do the steps listed here on this tutorial: http://answers.unity3d.com/questions/35480/crosshair-how.html, seeing as I do not want a crosshair that moves all over the place, but not only did the crosshair not even show up, since I had changed my camera to Depth Only it made the whole scene look distorted when I looked upwards. I tried making a second camera instead of using my main, but then it gave me two overlaid scenes, one of which moved when I looked around and one which didn’t. The other tutorials just didn’t work.
Obviously I’m doing something wrong, and if anyone could let me know what’s a better idea for a crosshair that DOESN’T screw up the scenery, that’d be great.
Thank you!
Why not go GameObject > Create Other > GuiTexture, put your texture in there, make the correct resolution, then attach this script to it:
function Update () {
guiTexture.transform.position.y = Screen.height / 2;
guiTexture.transform.position.x = Screen.width / 2;
}
WARNING: Un-tested code
The simplest solution is to use a GUITexture or a GUI.DrawTexture. For GUITexture:
- Game Object > Create Other > GUITexture
- Drag and drop a new texture on the ‘texture’ variable in the newly created GUITexture
- Edit the PixelInset values to reflect the new texture. Note that x and y of the PixelInset are negative and 1/2 of the width and height of the texture.
As for your list above, there are a few steps missing or are better handled in the latest version of Unity:
- Use a Quad rather than a Plane for display
- You have to create and set a layer for the Quad/Plane
- You have to set the culling mask for both cameras, so that only the second camera see the crosshair.
- It would be best if the second camera was Orthographic
Note the GUITexture solution has two drawbacks. First, if you are targeting multiple devices with multiple resolutions, you’ll need to add code to scale your GUITexture. You don’t need scaling with the Quad/Plane solution. Second, it is possible with the Quad/Plane solution to use a texture atlas and therefore eliminate one draw call (only important for mobile and a more advanced topic).