- Home /
Enable and disable options
Hi, I am making a scene with a first-person controller (moving a camera by using WSAD keys and rotating the camera by moving the mouse), Cube and UI Panel. My goal is the following: 1) Activate an UI Panel when I click on the Cube; 2) When the UI Panel appears, the first-person controller should be inactive so I can interact with the elements in the UI Panel; 3) Hide the UI Panel by clicking on a certain button in it (example the “X” button) and be able to walk and turn the camera in my scene again. I have already made the scripts of the ‘First-person controller’ and to ‘Cast a ray’ and ‘Detect’ an object. What I need is help for Enabling/Disabling the UI Panel. Then, when the UI Panel is shown on the screen, the first-person controller should be paused and again activated when the UI Panel is closed.
The code for detecting an object:
using System.Collections;
using UnityEngine;
public class CLickAction : MonoBehaviour
{
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray toMouse = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit rhInfo;
bool didHit = Physics.Raycast(toMouse, out rhInfo, 500.0f);
if (didHit)
{
//Call a funcion which will show the Panel
//Desable a function that moves camera by mouse movement.
}
else
{
}
}
}
}
Answer by wewewu · Jul 19, 2020 at 05:16 PM
I think you can put you movement script in a separate code and disable it.
Your answer

Follow this Question
Related Questions
Enable and Disable a plane 1 Answer
Why this script doesn't work? (Disable Component) 1 Answer
How to Disable an Interface 2 Answers