- Home /
how can i disable camera movement
this script brings up a GUI menu when the "E" key is pressed , the problem is that i when i scroll over to the buttons, the camera moves with the mouse, so what im asking here is how can i disable any movement from the camera or player (like disable the third person controller and the mouse orbit script on the camera)
using UnityEngine;
using System.Collections;
public class guiskin : MonoBehaviour
{
//variables start*********************************************************************
public GUISkin thisOrangeGUISkin;
public bool MenuState = false;
private Rect rctWindow1;
private Rect rctWindow2;
private Rect rctWindow3;
private Rect rctWindow4;
private bool blnToggleState = false;
private float fltSliderValue = 0.5f;
private float fltScrollerValue = 0.5f;
// private Vector2 scrollPosition = Vector2.zero;
//variables end***********************************************************************
void Update(){
if(Input.GetKeyDown(KeyCode.E)){
MenuState = !MenuState; // toggle MenuState
}
}
void Awake()
{
rctWindow1 = new Rect(Screen.width*.75f, 20, 320, 400);
}
void OnGUI()
{
if(MenuState == true){
GUI.skin = thisOrangeGUISkin;
rctWindow1 = GUI.Window(0, rctWindow1, DoMyWindow, "OPTIONS");//, GUI.skin.GetStyle("window"));
}}
void DoMyWindow(int windowID)
{
GUILayout.BeginVertical();
GUILayout.Button("Pokedex");
GUILayout.Space(8);
GUILayout.Button("Pokemon");
GUILayout.Space(8);
GUILayout.Button("Bag");
GUILayout.Space(8);
GUILayout.Button("Trainer");
GUILayout.Space(10);
GUILayout.Button("Save");
GUILayout.Space(10);
GUILayout.Button("Options");
// GUILayout.TextField("Im a textfield");
//GUILayout.TextArea("Im a textfield\nIm the second line\nIm the third line\nIm the fourth line");
//blnToggleState = GUILayout.Toggle(blnToggleState, "Im a Toggle button");
GUILayout.EndVertical();
// GUILayout.BeginVertical();
//Sliders
/*GUILayout.BeginHorizontal();
fltSliderValue = GUILayout.HorizontalSlider(fltSliderValue, 0.0f, 1.1f, GUILayout.Width(128));
fltSliderValue = GUILayout.VerticalSlider(fltSliderValue, 0.0f, 1.1f, GUILayout.Height(50));
GUILayout.EndHorizontal();
//Scrollbars
GUILayout.BeginHorizontal();
fltScrollerValue = GUILayout.HorizontalScrollbar(fltScrollerValue, 0.1f, 0.0f, 1.1f, GUILayout.Width(128));
fltScrollerValue = GUILayout.VerticalScrollbar(fltScrollerValue, 0.1f, 0.0f, 1.1f, GUILayout.Height(90));
GUILayout.Box("Im\na\ntest\nBox");
GUILayout.EndHorizontal();
GUILayout.EndVertical();*/
GUI.DragWindow();
}
}
Answer by Julien-Lynge · Jun 30, 2012 at 12:30 AM
You either have to modify your camera script directly (it sounds like you're using a MouseLook script?) so that input can be disabled through a method, or disable the entire script directly. Here's perhaps the simplest way:
Add a public variable to your GUI script:
public [CameraScript] cameraScript;
Where [CameraScript] is the type/name of the camera script, e.g. MouseLook. In the editor, assign the script you want to disable to this variable. You can do the same for character controllers, etc.
Then, when you want to stop the camera/whatever from moving:
cameraScript.enabled = false;
And when you want to re-enable it:
cameraScript.enabled = true;
Note: you may have to convert to a behaviour before you can access enabled - I don't remember offhand:
((Behaviour)cameraScript).enabled = true/false;
alternatively:
(cameraScript as Behaviour).enabled = true/false;
Good luck!
yes ty sooo much ...lol i just changed the
cameraScript.enabled = false;
into cameraScript.enabled =!cameraScript.enabled and did the rest like u said ..and it worked ty..
Your answer
Follow this Question
Related Questions
how can I disable all camera movements trough GUI? 2 Answers
First person camera restriction. 1 Answer
Moving forward in 3D 1 Answer
Constrain axis of isometric camera ("vertical" only) 0 Answers