• 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 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 this? 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
Add comment · 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<$$anonymous$$ouseLook>().enabled = true;


Although, it's better in the future if you just keep a reference of that within the script itself, ins$$anonymous$$d 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($$anonymous$$ouseLook)).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
1
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:

(Within FirstPersonController.cs) At the top, add a new variable:

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


(Within FirstPersonController.cs) At the bottom, there will be a function called RotateView. Replace it with this:

 private void RotateView ()
 {
     if (this.mouseLookEnabled)
         m_MouseLook.LookRotation (transform, m_Camera.transform);
 }


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

 public FirstPersonController firstPersonController;


Then replace your GetComponent().enabled calls with:

 this.firstPersonController.mouseLookEnabled = true;
Comment
Add comment · 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 NikichaTV · 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_$$anonymous$$ouseLook and the other vars come from. I am using exactly the same $$anonymous$$ouseLook script and Pause$$anonymous$$enu - 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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Stop Unity from freezing on NullReferenceExceptions ? 1 Answer

Problem with the camera, 2D. 0 Answers

Object reference not set to an instance of an object. ( FirstPersonController) 1 Answer

Multiple Targets Camera 1 Answer

Does anyone know why this simple player camera lock script is not working? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges