• 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
Question by tuomvii · Mar 14, 2018 at 03:49 PM · scripting problemcamera-movementfreezemouselookpause menu

I need to freeze Camera movement from FirstPersonController

I am getting "UnityStandardAssets.Characters.FirstPerson.MouseLook is a type but a variable was expected" error. How I fix t$$anonymous$$s? I want to freeze my camera movement when a player enters Pause Menu.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityStandardAssets.Characters.FirstPerson;
 
 public class PauseMenu : MonoBehaviour {
 
     public static bool GameIsPaused = false;
     public GameObject pauseMenuUI;
 
     void Start()
     {
     }
 
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.Escape))
         {
             if (GameIsPaused)
             {
                 Resume();
             } else
             {
                 Pause();
             }
         }
     }
 
     void Resume ()
     {
         pauseMenuUI.SetActive(false);
         Time.timeScale = 1f;
         GameIsPaused = false;
         GetComponent(MouseLook).enabled = true;
 
     }
 
     void Pause ()
     {
         pauseMenuUI.SetActive(true);
         Time.timeScale = 0f;
         GameIsPaused = true;
         GetComponent(MouseLook).enabled = false;
     }
 }

Comment

People who like this

0 Show 14
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 TreyH · Mar 14, 2018 at 03:55 PM 0
Share

GetComponent has a type-argument that uses a different syntax. Change those to look like this:

 GetComponent<MouseLook>().enabled = true;


Although, it's better in the future if you just keep a reference of that within the script itself, instead of getting that component each time -- like you're already doing with the UI.

avatar image Vicarian TreyH · Mar 14, 2018 at 04:01 PM 1
Share

If you aren't comfortable with the generic syntax for GetComponent, you may use

 GetComponent(typeof(MouseLook)).enabled = true;

in this case.

avatar image tuomvii Vicarian · Mar 14, 2018 at 04:06 PM 0
Share

Visual Studio just says that "Component doesn't contain a definition for enabled etc...".

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by TreyH · Mar 14, 2018 at 05:00 PM

So, MouseLook isn't a component.

It's a helper class for Unity's standard FirstPersonController, and the FirstPersonController doesn't let you do that out-of-the-box. But, you can add that functionality pretty easily. Edit that FirstPersonControllerScript accordingly:

(Wit$$anonymous$$n FirstPersonController.cs) At the top, add a new variable:

 // Add t$$anonymous$$s to the top of FirstPersonController's variable declarations;
 public bool mouseLookEnabled = false;


(Wit$$anonymous$$n FirstPersonController.cs) At the bottom, there will be a function called RotateView. Replace it with t$$anonymous$$s:

 private void RotateView ()
 {
     if (t$$anonymous$$s.mouseLookEnabled)
         m_MouseLook.LookRotation (transform, m_Camera.transform);
 }


(Wit$$anonymous$$n PauseMenu.cs or wherever it's declared) At the top, add a new variable. You will need to assign t$$anonymous$$s in the inspector before you run the scene.

 public FirstPersonController firstPersonController;


Then replace your GetComponent().enabled calls with:

 t$$anonymous$$s.firstPersonController.mouseLookEnabled = true;
Comment
tuomvii

People who like this

1 Show 5 · 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 tuomvii · Mar 14, 2018 at 05:11 PM 0
Share

Thank you, that did the job! Appreciate the help!

avatar image TreyH tuomvii · Mar 14, 2018 at 05:14 PM 0
Share

np! If the answer solved your problem, please mark it as the correct solution so that this thread can be closed.

avatar image tuomvii TreyH · Mar 14, 2018 at 05:16 PM 0
Share

Sure! The only thing is that i guess that CursorLock is disabled until i click once after I go back from Pause. Dont know if it will be visible in the end product, but i guess i deal with it later.

Show more comments
avatar image NixyNick · Nov 12, 2020 at 09:55 AM 0
Share

Sorry, but I have the same problem. I tried doing what you said but for some reason I get an error and I don't really understand where do m_MouseLook and the other vars come from. I am using exactly the same MouseLook script and PauseMenu - by Brackeys, right? Can you copy your pause menu and mouse look and send them to me, because this way I might be able to undestand them once they are written. Thanks in advance! @TreyH

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

143 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 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 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 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 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 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 script for ball not working as intended, looking for some tips, or advise. 0 Answers

Stop Unity from freezing on NullReferenceExceptions ? 1 Answer

Cinemachine 'DocumentationSortingAttribute' does not contain a constructor that takes 2 arguments 1 Answer

Rotate camera around object and let it centered 0 Answers

Camera Panning script is inconsistent 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