When AC's cursor is locked, it can optionally be displayed in the centre of the screen. However, it will still use the "Main cursor" texture assigned in the Cursor Manager.
This script allows you to display a separate texture, such as a crosshair, on-screen when the cursor is locked. To use it:
- Create a new C# script named Crosshair, and copy/paste the code below.
- Add a new Unity UI Canvas to the scene, and add an Image with a crosshair texture to it as a child, positioned in the centre of the screen.
- Add a Canvas Group component to the Canvas' root, and uncheck Interactable.
- To the same GameObject, add the new Crosshair component, and assign the Canvas Group in its Inspector.
- In AC's Settings Manager, check Hide cursor when locked in screen's centre?.
Crosshair.cs:
using UnityEngine;
using AC;
public class Crosshair : MonoBehaviour
{
public CanvasGroup canvasGroup;
private void Update ()
{
if (canvasGroup) canvasGroup.alpha = KickStarter.playerInput.IsCursorLocked () ? 1f : 0f;
}
}