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
0
Question by Ivan Ich · May 23, 2013 at 11:04 PM ·

error CS0120 in Unity script

Hi guys, I'm getting this error in unity: Assets/Standard Assets/Scripts/General Scripts/ActivateTrigger.cs(53,52): error CS0120: An object reference is required to access non-static member `UnityEngine.GameObject.SetActive(bool)'

This code gives me the error:

 break;
                     case Mode.Activate:
                         targetGameObject.SetActive(true); 
                         break;
                     case Mode.Enable:
                         if (targetBehaviour != null)
                             targetBehaviour.enabled = true;
                         break;    
                     case Mode.Animate:
                         targetGameObject.animation.Play ();
                         break;    
                     case Mode.Deactivate:
                         GameObject.SetActive = false;
                         break;
Comment
Add comment · Show 1
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 Benproductions1 · Jun 03, 2013 at 04:21 AM 1
Share

Please accept an answer or close the question

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Benproductions1 · May 23, 2013 at 11:13 PM

Hello,

When you are trying to access the GameObject your script is attached to, you need to put it in lower case: gameObject.
It's the difference between accessing a recipe and a cake following the recipe (I like cake metaphors)

Another problem is that SetActive is a function, more specifically a method, so instead you have to call it and pass it either true or false, instead of trying to set it to true or false.
Usually, unless your using .NET classes, every variable in Unity is non-capitalised and every function/class is capitalised, so you know something is wrong when your trying to set something thats capitalised :)

Hope this helps, Benproductions1

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
avatar image
0

Answer by robertbu · May 23, 2013 at 11:05 PM

Line 13, game object should be lower case and SetActive() is a method:

 gameObject.SetActive(false);
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 Ivan Ich · May 24, 2013 at 07:41 AM 0
Share

I fixed the error I had thanks to the code robertbu gave me but then a lot more mistakes appeared in different script codes such as: Assets/Editor/CutsceneBirdsEditor.js(11,46): BCE0018: The name 'CutsceneBirds' does not denote a valid type ('not found'). Did you mean 'System.CodeDom.Compiler.CodeCompiler'?

Assets/Editor/CutsceneBirdsEditor.js(20,28): BCE0018: The name 'Seagull' does not denote a valid type ('not found'). Did you mean 'UnityEngine.Social'?

$$anonymous$$y question is why do I even care about this script when it isn't even something I use in my game. It's just in the assets. Can I just delete the scripts that give me an error? I started getting script errors all of a sudden, wasn't even tweaking the scripts as I'm not a coder.

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

14 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

do you know what version of unity was released in the end of 2012? 0 Answers

Animating a cubemaps orientation 1 Answer

How to import the object from server to unity 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers


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