PauseMenu class error

In the RPG Core Combat Creator - Archived Course, in the lesson 10 ‘Using Raycasts To Query Click’
when i wrote this code in the Cursor Class:

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

public class Cursor : MonoBehaviour
{  
    CameraRaycaster CameraRaycaster;

    void Start()
    {
        CameraRaycaster = GetComponent<CameraRaycaster>();
    }

    void Update()
    {
        print(CameraRaycaster.layerHit);
    }
}

it appears in the PauseMenu class this error

using System;
using UnityEngine;
using UnityEngine.UI;

public class PauseMenu : MonoBehaviour
{
    private Toggle m_MenuToggle;
    private float m_TimeScaleRef = 1f;
    private float m_VolumeRef = 1f;
    private bool m_Paused;
    void Awake()
    {
        m_MenuToggle = GetComponent <Toggle> ();
    }

    private void MenuOn ()
    {
        m_TimeScaleRef = Time.timeScale;
        Time.timeScale = 0f;
        m_VolumeRef = AudioListener.volume;
        AudioListener.volume = 0f;
        m_Paused = true;
    }

    public void MenuOff ()
    {
        Time.timeScale = m_TimeScaleRef;
        AudioListener.volume = m_VolumeRef;
        m_Paused = false;
    }

    public void OnMenuStatusChange ()
    {
        if (m_MenuToggle.isOn && !m_Paused)
        {
            MenuOn();
        }
        else if (!m_MenuToggle.isOn && m_Paused)
        {
            MenuOff();
        }
    }

#if !MOBILE_INPUT

    void Update()
    {
        if(Input.GetKeyUp(KeyCode.Escape))
        {
            m_MenuToggle.isOn = !m_MenuToggle.isOn;
            Cursor.visible = m_MenuToggle.isOn;//force the cursor visible if anythign had hidden it
        }
    }

#endif
}

I wouldn’t have expected Cursor to exist on mobile but the documentation does say it falls back to software on unsupported platforms. Since you don’t have a mouse, is it a good idea to try to have a cursor if you’re on mobile?

Actually, before reformatting the code, it looked like it was #if MOBILE_INPUT, but it was actually #if !MOBILE_INPUT, in which case you’d be dealing with keystrokes and mouse input…

When you created a class Cursor, you essentially hid the built in Unity Cursor class.

Given that the Cursor class you’re using exists only to show the layer that the CameraRaycaster has hit, I think you’re better off renaming that class to something like CursorLayerDebugger. Once this is done, then Cursor.visible (a static method in UnityEngine.Cursor class) should work as intended.

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

Privacy & Terms