I'm getting these errors when trying to organize my script

I’m getting two when trying to organize my script. here are the errors:

Assets\Scripts\MouseWorld.cs(11,8): error CS0103: The name ‘instance’ does not exist in the current context

and

Assets\Scripts\MouseWorld.cs(22,72): error CS0103: The name ‘instance’ does not exist in the current context

and here is my script:
using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class MouseWorld : MonoBehaviour

{

[SerializeField] private LayerMask mousePlaneLayerMask;

private void Awake()

{

   instance = this;

}



void Update()

{

    transform.position = MouseWorld.GetPosition();

}

public static Vector3 GetPosition()

{

    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

   Physics.Raycast(ray, out RaycastHit raycastHit, float.MaxValue, instance.mousePlaneLayerMask);

   return raycastHit.point;

}

}

if someone could help that would be great

never mind I fixed the problem by simply adding this line private static MouseWorld instance; to the script

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms