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 TheKnight · Oct 13, 2011 at 03:12 PM · javascripttriggerlightswitch

Light switch trigger

I am having a bit of difficulties with the switch light sensor(although it's more of a button sensor).I've made this simple code and it doesn't work.

 var switchLight : Transform;
 
 function Update () {
 
     if(Input.GetKey("q"))
     {
     
         switchLight.enabled = true;
     
     }
     else if(Input.GetKey("t"))
     {
         switchLight.enabled = false;
     } 

It gets an error : Field "UnityEngine.Transform.enabled" not found.

Hasn't it been declared as a boolean? Is that the mistake?

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

Answer by Inan-Evin · Oct 13, 2011 at 03:17 PM

You can't enable or disable the transform. If it's a point light or another kind of light you should do :

 var light : Transform;
 
  light.intensity =0; // set the intensity to 0 , which will give no light.

Or if it's just a value that you wan't to make false or true, yes you should use boolean.

 var light : boolean = 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 TheKnight · Oct 13, 2011 at 03:38 PM 0
Share

Yes, thank you I fixed it as soon as I posted it, wanted to delete it but you answered my second question that I wanted to ask, how to change the light intensity. Thanks!

avatar image
0

Answer by leonalchemist · Oct 13, 2011 at 04:03 PM

very simple fix :P

 var switchLight : GameObject;

OR

 var switchLight : Light;

because u want to change the value of a GameObject's component not the transform component(transform is only for changing position, rotation or scale), and to make only one button

 function Update()
 {
     if (Input.GetKeyDown(KeyCode.F))
     {
         light.enabled = !light.enabled;
     }
 }
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 TheKnight · Oct 13, 2011 at 04:43 PM 0
Share

Yes, figured it out, though a nice explanation for the transform component, as funny as it sounds, didn't know that.

avatar image
0

Answer by markmozza · Jan 21, 2019 at 11:56 AM

New 2019 Tutorial https://www.youtube.com/watch?v=kqu-lsfd4qI&t=1s

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I loop my light animation is javascript? 1 Answer

Switching Cameras - Confusion with Two Code Samples 2 Answers

Camera switching : C# onTriggerEnter not working 1 Answer

Trouble with light switch 3 Answers

What’s wrong with my Safe Volume (safe zone) code? 0 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