Skip to main content

Getting started

Before you add a crosshair to a scene, you must decide which crosshair to use. There are three types of crosshairs available. The following documentation pages provide more information about each crosshair type and also explain how to create and configure each one:

Add a crosshair to a scene

After you decide which crosshair type to use, you can add it to a scene. To make it simple to set up each crosshair, the crosshair component editor provides a Generate Crosshair GameObject button. This automatically generates a crosshair Canvas, if one doesn't already exist, and creates the other GameObjects and components required to render the crosshair.

To add a new crosshair to a scene:

  1. Create a new GameObject.
  2. Attach the crosshair component of your choice to the GameObject.
  3. In the Inspector for the component, click Generate Crosshair GameObject.
  4. To change the crosshair's appearance in the Editor, modify property values in the component.

If you have multiple Canvases in your scene, the crosshair might be hidden behind another Canvas. To move the Crosshair Canvas to the front, increase the Sorting Order value in the Inspector.

Modify a crosshair at runtime

Every crosshair type inherits from SimpleCrosshairBase which provides a unified API to work with all crosshair types. This means that you can use the same code to configure and control all crosshair types.

The following code sample shows how to modify a crosshair's gap at runtime:

public static class ModifyCrosshairExample
{
public void SetGapExample(SimpleCrosshairBase SimpleCrosshair)
{
int curGap = SimpleCrosshair.GetGap();
SimpleCrosshair.SetGap(curGap + 2, true);
}
}

The asset includes demo scenes and example scripts that show how to use the crosshair API. You can find them in the Assets/Simple Crosshair Plus/Demo Scenes folder. For more information, see Demo scenes.

Additional resources