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
1
Question by mika132 · Sep 07, 2012 at 01:10 PM · cameraanglemovingstopping

Stopping camera

Why this not work? Do i something wrong?

         private GameObject firstPersonControllerCamera;
         private GameObject mainCamera;
 
         void Update (){
             if(enter == true){
                if(Input.GetKeyDown("f")){
                     TalkingMenu = 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;
                }
             }
         }

It's make error: Static member `UnityEngine.GameObject.Find(string)` cannot be accessed with and instance reference, qualify it with a type name instead

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
0

Answer by aldonaletto · Sep 07, 2012 at 02:32 PM

You should use GameObject.Find("name"). But there are other errors: mainCamera and firstPersonControllerCamera types should be MouseLook, not GameObject. Additionally, you should assign them only once (at Start, for instance) in order to avoid possible hiccups when pressing F (Find functions are slow). Since the First Person Controller prefab has the tag "Player", is easier and faster to find it by tag. The main camera is easier: the Camera.main variable is a Camera reference that shows which's the main camera.

private MouseLook firstPersonControllerCamera; private MouseLook mainCamera;

     void Start(){
         // It's easier to find the FPC by its tag:
         GameObject player = GameObject.FindWithTag("Player");
         firstPersonControllerCamera = player.GetComponent< MouseLook>();
         // No need to Find the main camera: use Camera.main instead:
         mainCamera = Camera.main.GetComponent< MouseLook>();
     }

     void Update (){
         if(enter == true){
            if(Input.GetKeyDown("f")){
                TalkingMenu = true;
                Screen.lockCursor = false;
                firstPersonControllerCamera.enabled = false;
                mainCamera.enabled = false;
            }
         }
     }

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

8 People are following this question.

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

Related Questions

360 Angle Camera Rotate 2 Answers

MissingComponentException: There is no 'Camera' 0 Answers

Final Fantasy style camera 1 Answer

Movin' camera in XYZ 6 Answers

How to make Orthographic camera ignore window size changes? 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