• 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.

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

8 People are following this question.

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

Related Questions

Get the gameobject to the left/right of current target, in field of vision? 0 Answers

Object jitters when camera is moving and is in the near? 0 Answers

About Camera 1 Answer

Toggle map/Camera [JS] 1 Answer

Why doesn't my players camera work and why does it spaz out randomly 1 Answer

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