mouse manager script not working!!!!!

i created a mouse manager script learned from unity learn and i have double checked my script but its not working…

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class Mouse_Manager : MonoBehaviour
{
    public LayerMask clickablePlayer;

    public Texture2D pointer;
    public Texture2D target ;
    public Texture2D doorway;
    public Texture2D combat;
    private bool Defaultvalue = false;
   

   
    private void Update()
    {
        RaycastHit hit;

        if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 50, clickablePlayer.value))
        {
            bool door = Defaultvalue;
            if (hit.collider.gameObject.tag == "Doorway")
            {
                Cursor.SetCursor(doorway, new Vector2(16, 16), CursorMode.Auto);
                door = true;
            }
            else
            {
                Cursor.SetCursor(target, new Vector2(16, 16), CursorMode.Auto);
            }

        }
        else
        {
            Cursor.SetCursor(pointer, new Vector2(0,0) , CursorMode.Auto);
        }
    }
}

Hi and welcome.
Generally speaking, you want to include as much helpful information as possible.

“It’s not working” is basically useless in terms of helping you. What is not working? What is it supposed to do, what is it doing instead? Is it throwing errors? If so, which one, including the full error message (and if you, for example, only posted a part and not the full script, you’d want to include which line the error occurs on in the posted code example).

1 Like

thankyou for replying yes i will provide you with full info…

i was trying to change cursor in game whenever cursor reaches to object for example a door icon when cursor is placed on door in environment.
i take a empty game object as mouse manager and then added above script to it… i creacted a new layer clickable and set my door to clickable layer and Doorway tag to door as required by code but when i compile all them and start game no cursor changes!!!

compiler is showing this error…
NullReferenceException: Object reference not set to an instance of an object
Mouse_Manager.FixedUpdate () (at Assets/Scripts/Mouse_Manager.cs:22)

It looks like you don’t have a Camera with the tag “MainCamera” in the scene. This causes Camera.main to return null, which causes the NullReferenceException.

Yeah, either the (main) camera does not exist, or you maybe forgot to assign clickablePlayer in the inspector.

@Yoreki both of them are done