I tried adding the following script to an empty game object but I got the following error: “Can’t add script behaviour AssemblyInfo.cs. The script needs to derive from MonoBehaviour!”
Does anyone know what might cause this problem?
Thanks in advance!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LOCKANDUNLOCK : MonoBehaviour
{
public bool GamePause = false;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
if(Input.GetKeyDown(KeyCode.Escape))
{
if(GamePause)
{
ResumeAndLock();
}
else
{
PauseAndUnlock();
}
}
}
void ResumeAndLock()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
GamePause = false;
}
void PauseAndUnlock()
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
GamePause = true;
}
}