Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 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 BinaryCaveman · Dec 21, 2010 at 11:10 PM · errorgetcomponentenabledcs0246

Disabling a Script with C#

I am trying to create a script disable another script attached to the same GameObject.

I am using the following line:

 GetComponent<ScriptName>().enabled = false;

However, I get this error:

error CS0246: The type or namespace name 'ScriptName' could not be found. Are you missing a using directive or an assembly reference?

What am I doing wrong? Thank you in advance!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by BinaryCaveman · Dec 22, 2010 at 04:19 AM

I found a solution to my problem.

Although it is probably not the best possible solution, I placed the scripts I was referring to in the Standard Assets folder inside my project.
In this way, Unity compiles the scripts I was referring to before the script in which I wrote GetComponent<ScriptName>(). (See the Unity documentation for more info)

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 BlastOffProductions · Sep 22, 2017 at 05:53 PM 0
Share

Thanks, that works perfect! Iv'e been working a few hours trying to figure this out, and finally I found your answer!

avatar image
1

Answer by Proclyon · Dec 21, 2010 at 11:19 PM

ScriptName is not a type that exists in your scope. Most of the time that just means you got the name wrong. But with the current information , that's all I can guess. Either that or you built it in some other project or library that isn't included yet and you need to import it with a using reference, the compiler friendly as it is, assuming you never make a typo.

Comment
Add comment · Show 2 · 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 BinaryCaveman · Dec 21, 2010 at 11:31 PM 0
Share

This script is in C#, where the other script is in JavaScript. Does that make a difference?

avatar image BinaryCaveman · Dec 23, 2010 at 09:25 PM 0
Share

Rather, do C# scripts compile before JavaScripts?

avatar image
0

Answer by NinjaEntertainment · Sep 22, 2017 at 07:52 PM

Hello. First that script u are disabling must exist. you need to change that ScriptName to real scriptname to your REAL script name instead of "ScriptName"

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

2 People are following this question.

avatar image avatar image

Related Questions

Error with unify code? 1 Answer

Unexpected token ) when dealing with getcomponent 1 Answer

C# getComponent result error cast 3 Answers

Enable script on parent 2 Answers

I am getting a error CS0246: 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