1
\$\begingroup\$

I want to center it to the middle of screen.

And the size i tried to make both width and height * 0.02f but it's still too big when running the game.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;

public class RotateObject : MonoBehaviour
{
    public Texture2D cursorTexture;
    public CursorMode cursorMode = CursorMode.Auto;
    public bool autoCenterHotSpot = false;
    public Vector2 hotSpotCustom = Vector2.zero;
    private Vector2 hotSpotAuto;

    void Awake()
    {
        Cursor.lockState = CursorLockMode.Locked;

        Vector2 hotSpot;
        if (autoCenterHotSpot)
        {
            hotSpotAuto = new Vector2(cursorTexture.width * 0.02f, cursorTexture.height * 0.02f);
            hotSpot = hotSpotAuto;

        }
        else { hotSpot = hotSpotCustom; }

        Cursor.SetCursor(cursorTexture, hotSpot, CursorMode.ForceSoftware);
    }
}

In the screenshot the mouse cursor is the image on the left in the game view and it's not in the center it's a bit on the right bottom(The ball is the mouse cursor). On the right the inspector of the script. The script is attached to the FPSController.

new mc

\$\endgroup\$
  • 1
    \$\begingroup\$ If you're centering the cursor texture, then does it matter that it's a cursor at all? How is this different from displaying & sizing any UI image centered in the screen? \$\endgroup\$ – DMGregory Nov 10 '17 at 20:53
  • \$\begingroup\$ @DMGregory Right. I added a Image (Script) component and set as source image UISprite Color set to red and created new material and added it to the Image also in red. Raycast target is on/checked , sliced and fill center also on/checked. But how do i display it now in the center of screen ? \$\endgroup\$ – user1196715 Nov 10 '17 at 21:24

Your Answer

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

Browse other questions tagged or ask your own question.