Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Hatdatsat · Jul 24, 2017 at 08:14 AM · error messageboolget

if statement in a get function

So I'm working on a project with a camera where i have the camera but other team members don't so i have 2 different object groups 1 virtual and 1 that works with the camera. So I'm trying t make a index script that checks what your using and grabs all the info needed so are you using camera? grab fov from the camera, are you using virtual? grab fov virtual and set them as a get function so what i tried was this:

 public static float get_FOV(){
         if (virtuEnabled) {
             return CameraCapture.getfovY;
         } else {
             return MouseLook.getFOV;
         }     
     }

i also tried it like this:

 public static float get_FOV {
         get {
             if (virtuEnabled) {
                 return CameraCapture.getfovY;
             } else {
                 return MouseLook.getFOV;
             }     
         }
     }

the virtuEnable is a bool set true or false depending what your using. now the problem that im having is that it gives me this error Assets/Scripts/varLibrary.cs(47,7): error CS0120: An object reference is required to access non-static member `varLibrary.virtuEnabled' line 74 is refering to the if (virtuEnabled) {

any help in this matter would help alot!

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
2
Best Answer

Answer by tanoshimi · Jul 24, 2017 at 09:26 AM

That's because you've declared the get_FOV function static, but the virtuEnabled variable it tries to access is not.

If this is meant to be a single, shared, class-level function, use the static modifier with both the get_FOV function and the virtuEnabled variable declaration. Alternatively, if this is meant to be an instance function, remove the static modifier from both.

Comment
Add comment · Show 1 · 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 Hatdatsat · Jul 24, 2017 at 10:02 AM 0
Share

On all my previous public float get function it never wanted to work without static but i tried

public float get_FOV { get { if (virtuEnabled) { return CameraCapture.getfovY; } else { return $$anonymous$$ouseLook.getFOV; }
} }

and somehow it works thanks a lot!

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

69 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

Related Questions

operator && cannot be applied to operands of type bool and method group 1 Answer

Store a reference to an object with a certain boolean? 0 Answers

how to stop the player when gameover?? 1 Answer

Unity plays the animation then jumps to another, then back again. 0 Answers

Double collision on "ground" tagged object results in player thinking they're in air? 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