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 /
This question was closed Aug 09, 2013 at 05:15 PM by clunk47 for the following reason:

The question is answered, right answer was accepted

avatar image
2
Question by Eddy Johnson · Oct 01, 2011 at 09:10 PM · componentenabledhalo

How to disable/enable Halo component via script

Is it possible to control the Halo component similar to the other components? Something like:

 renderer.enabled = false;
 collider.enabled = false;

GetComponent("Halo").enabled = false; did not work for me aswell ( 'enabled' is not a member of 'UnityEngine.Component'. )

Comment
Add comment · Show 3
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 Jason B · Oct 01, 2011 at 11:49 PM 0
Share

If you're using C#, you need to do "GetComponent().enabled = false;" ins$$anonymous$$d. The one Save referenced you to is a JavaScript-only implementation and the syntax won't be correct for C#.

avatar image clunk47 · Jul 26, 2013 at 03:44 PM 0
Share

You need to access the component, then a variable within the component. For example, say you have a script attached to your camera, and you want to disable that camera's "Camera" component. You would by just accessing Component("Camera"), calling the variable, then using enabled = true / false like so (if you're using a string):

 GetComponent("Camera").camera.enabled = false;

But notice there is a string in GetComponent? If you DON'T use a string, you could do like so:

 GetComponent(Camera).enabled = false;
avatar image clunk47 · Aug 09, 2013 at 05:12 PM 0
Share

PLEASE LET US $$anonymous$$NOW IF ONE OF THE ANSWERS HERE PROVIDES A PROPER SOLUTION.

2 Replies

  • Sort: 
avatar image
2
Best Answer

Answer by save · Oct 01, 2011 at 09:16 PM

The Halo component isn't connected to the renderer class. You'd have to do this:

GetComponent(Halo).enabled = false;

If it doesn't work, where are you calling it from and how? Just tested on the GameObject and it works well.

Comment
Add comment · Show 3 · 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 eddyjohnson3 · Oct 02, 2011 at 02:52 PM 0
Share

I am calling it in a script attached to a prefab, which will be instantated during gameplay. Prefab also has a collider used as a trigger and a Halo component. I need to disable some components once something hits the trigger collider:

function OnTriggerExit(other : Collider) { Destroy(other.gameObject);

 GetComponent("Halo").enabled=false;
 renderer.enabled = false;
 collider.enabled = false;    

}

But I get "BCE0019: 'enabled' is not a member of UnityEngine.Component'. " on line GetComponent("Halo").enabled=false;

PS Sorry I am using a different acount, but I could not log in anymore...

avatar image AaronC · Mar 19, 2012 at 09:58 PM 0
Share

This technique does not compile for iOS

avatar image rutter · Mar 20, 2012 at 06:57 AM 0
Share

I find it's better to pass a type argument to GetComponent().

GetComponent("Halo") returns a Component reference.

GetComponent(Halo) returns a Halo reference.

The difference is crucial if you're using static typing.

avatar image
15

Answer by eormeno · Jul 26, 2013 at 03:39 PM

Component halo = GetComponent("Halo"); halo.GetType().GetProperty("enabled").SetValue(halo, false, null);

Comment
Add comment · Show 4 · 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 maxmadman · Jul 07, 2014 at 02:35 AM 0
Share

Thanks eormeno. Your solution works for me. I'd vote it up but I don't have 15 points yet.

avatar image egui · Nov 14, 2014 at 05:39 PM 0
Share

Thanks eormeno, Your solution worked for me also.

avatar image Christop · Dec 23, 2014 at 03:14 PM 0
Share

thanks this also worked for me

avatar image Tanoshimi2000 · Feb 24, 2016 at 09:19 PM 0
Share

Any idea how to change the size of the halo in script? I only ask because changing this to "Size" doesn't work:

 Component halo = GetComponent("Halo");
         halo.GetType().GetProperty("Size").SetValue(halo, 0.5f + $$anonymous$$athf.Sin(Time.time), null);

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

BCE0019: 'enabled' is not a member of 'UnityEngine.Component' when using List 1 Answer

.enabled Problems 1 Answer

Cannot reference "Halo" type in Javascript 2 Answers

Adjusting size of a halo in C# 0 Answers

Is component.enabled Deprecated? Did it ever exist? 2 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