I’m making a game and I want to add a pause menu, but I need to freeze/lock the camera when I press Escape aka opening the pause menu. I’m using the first person controller from the standard assets asset and using c#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class testCamera : MonoBehaviour //Camera Script
{
private testInput _testInputSc;
void Start()
{
_testInputSc = FindObjectOfType<testInput>();
}
void Update()
{
Move();
}
void Move() //Move function
{
if (!_testInputSc._gameIsPaused)
{
transform.Translate(new Vector3(1,0,0));
}
}
}
CameraScript
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class testInput : MonoBehaviour //The input script
{
public bool _gameIsPaused = false;
void Update()
{
_gamePause();
}
private void _gamePause()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
_gameIsPaused = true;
}
else if (Input.GetKeyDown(KeyCode.Space))
{
_gameIsPaused = false;
}
}
}
Input script.
You can do it with such a simple method.