Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 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 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_$$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.

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

Change standart FirstPersonController variables via other script 2 Answers

Clamping Camera doesn't work 1 Answer

Many cameras with Camera.main.ScreenToWorldPoint trouble. 2 Answers

Pause menu Script not working 4 Answers

Rotating Sutff 1 Answer


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