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 Slasmir · Feb 11, 2012 at 11:56 PM · javascriptlight

Light problems

Hello im having a problem with some errors i get that i do not understand why im getteing. im posting a picture of my unity and my code below. this code should be able to turn on and off a torch. but i cant get it to work with the ligt.

Picture of the problem

The code is following:

 //Light script on / off
 
 var lightNr : int = 0;
 var OffLight    : float = 0.0;
 var OnLight        : float = 2.0;
 
 private var light : GameObject;
 
 function Start()
 {
     if(lightNr == 0)
     {
         isOn = true;
         light.intensity = OnLight;
     }
     else
     {
         isOn = false;
         light.intensity = OffLight;
     }
 }
 
 function TurnlightOn(nr : int)
 {
     if(nr == lightNr)
     {
         isOn = true;
         light.intensity = OnLight;
     }
 }
 
 function TurnlightOff(nr : int)
 {
     if(nr == lightNr)
     {
         isOn = false;
         light.intensity = OffLight; 
     }
 }

¨

I hope someone can put some light in my dark why this is not working.

Thanks alot for using your time on reading my question.

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

Answer by Berenger · Feb 12, 2012 at 02:12 AM

That's a little javascript trap you got here. As you don't need to write everything, you don't see that everything you write is part of a class inheriting from MonoBehaviour, which inherit from Component. Component have a property called light, without majuscule, which return GetComponent(Light). By calling your variable light, Unity is lost between your variable and Component's property. Give it another name and you'll be fine.

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 Slasmir · Feb 12, 2012 at 09:01 AM 0
Share

Hello thanks for your answer im just not sure that i understand it. you are saying give "it" another name. what do you mean by it ?

im aprisiating you taking your time to help me :)

avatar image Berenger · Feb 12, 2012 at 05:03 PM 1
Share

change "private var light : GameObject;" into "private var whateverNameYouLike : GameObject;"

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

Elevator script problem (Java) 1 Answer

Disable GameObject Only Father Not Children 2 Answers

GUI.Box within a Collider 1 Answer

Why is my script still running in other scenes? 1 Answer

Drag Script Not Working 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