Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by darkcookie · Jun 29, 2012 at 08:45 PM · cameramovementdisable

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();
     }
     
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

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!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image darkcookie · Jun 30, 2012 at 02:21 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

how can I disable all camera movements trough GUI? 2 Answers

First person camera restriction. 1 Answer

How to use Android Accelerometer(Left and right tilt) to turn a sphere object and camera in that direction? 1 Answer

Moving forward in 3D 1 Answer

Constrain axis of isometric camera ("vertical" only) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges