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 bigdaddychez · Mar 28, 2014 at 10:31 PM · cameracontrollerpause menupausegame

Lock camera when paused

When I pause my game I want the player camera to freeze, so when I move the cursor around to chose a menu option, the inGame camera doesn't move around. Here's my pause script. I added some code to try and fix this, and it looks right to me, but it doesn't work. I'd love some help with this problem. Tnx in advance

 var paused : boolean = false;
 var myCheck : boolean = false;
 
 function Start(){
    paused=false;
 }
 
 
 function Update () {
     if(Input.GetButtonDown( "Pause" ) ) {
     if(!paused) {
     Time.timeScale = 0;
     paused = true;
 Screen.lockCursor = false;
     firstPersonControllerCamera = gameObject.Find("First Person Controller").GetComponent("MouseLook");
     mainCamera = gameObject.Find("Main Camera").GetComponent("MouseLook");
     firstPersonControllerCamera.enabled = false;
     mainCamera.enabled = false;
     
 
     }else{
     Time.timeScale = 1;
     paused = false;
     
 Screen.lockCursor = true;
     firstPersonControllerCamera.enabled = true;
     mainCamera.enabled = true;
     
 
         }
     }
 }
 
 function OnGUI() {
     if( paused ) {
     
  if(GUI.Button (Rect ( 500, 90, 100, 30), "Restart" )) { 
     Time.timeScale = 1.0f;
     Application.LoadLevel( "stage2" );
     }
 
     if(GUI.Button (Rect ( 500, 130, 100, 30), "Options" )) {
     
     }
     
     if(GUI.Button (Rect ( 500, 170, 100, 30), "Quit" )) {
         }
     }
 }
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

2 Replies

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

Answer by robertbu · Mar 29, 2014 at 03:46 AM

To start with put at the top of the file:

  #pragma strict

When you do that you will find that your code will not compile. The first problem is that you don't declare 'firstPersonControllerCamera' and 'main' camera. The second problem is that you use the string version of GetComponent(). The string version returns an object of type 'Component', which does not have an enabled flag. You need to use the non-string version. Change lines 15 and 16 to the following:

 var firstPersonControllerCamera = gameObject.Find("First Person Controller").GetComponent(MouseLook);
 var mainCamera = gameObject.Find("Main Camera").GetComponent(MouseLook);
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 bigdaddychez · Mar 30, 2014 at 01:18 PM 0
Share

I appreciate your help ver much, but i solved the problem and now i feel like a complete idiot. It was actually as simple as this: I'd previously re-named "first person controller" in my project, I'd put "AA" in front of it, to put it at the top of my project view, but when i wrote the code I'd forgotten to use "gameobject.find("aa first person controller"), and only used the default name. Hope that can be a lesson for other people. The simplest things can bring you down. a single letter in a code is all it takes to ruin the whole thing. When i changed that, my code worked, but I will try out your's to see if It'll help me solve some another problem I'm having with my pause menu

avatar image
0

Answer by dizzymediainc · Apr 19, 2014 at 02:37 AM

With the needed additions mentioned above it indeed works just fine :)

(additions: FPS and main camera var )

Comment
Add comment · 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

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

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera stutters a lot when looking around (need help) 2 Answers

Issue with my camera controls 0 Answers

Pause Menu Wont Disable Mouse,Pause menu wont disable Player Controls 0 Answers

Freezes camera/controller when interacting with object 0 Answers

configure first person controller at runtime 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