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 Shiro_Rin · Mar 31, 2015 at 10:50 AM · lightinglightsthunder

Lighting script

I use a script to flicker lights to produce a lighting effect from a thunderstorm. However all my lights flash at different intervals. I tried making it an array of objects and to make them all flash at the same time using this code

 var lights: GameObject[];
 var flickerSpeed : float = 0.07;
 private var randomizer : int = 0;
 while (true) {
     if (randomizer == 0) {
         lights.GetComponent.<Light>().enabled = false;
     }
     else lights.GetComponent.<Light>().enabled = true;
     randomizer = Random.Range (0, 1.1);
     yield WaitForSeconds (flickerSpeed);
 }


However I get the error

 Assets/_Scripts/Flickerv2.js(6,16): BCE0019: 'GetComponent' is not a member of 'UnityEngine.GameObject[]'. 


Any help on a way to approach this is appreciated.

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

2 Replies

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

Answer by AlucardJay · Mar 31, 2015 at 11:59 AM

lights is an array. You need to specify what gameObject in the array you are trying to access :

 lights[ index ].GetComponent.<Light>().enabled = 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 Shiro_Rin · Mar 31, 2015 at 12:51 PM 0
Share

Thank you for the help, I've never used arrays before so I was kinda lost.

avatar image
0

Answer by trololo · Mar 31, 2015 at 11:07 AM

Oh yeah... (the guy below is right (and the guy below him seems even righter))

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 AlucardJay · Mar 31, 2015 at 11:58 AM 0
Share

that is incorrect.

 // uJS
 lights.GetComponent.<Light>().enabled = false;
 
 // C#
 lights.GetComponent<Light>().enabled = false;


http://wiki.unity3d.com/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use?#Generic_List

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Extrange Behaviour with 2D Lights in Universal RP 0 Answers

The light is not blending 0 Answers

Prefab asset lights differently in different scenes 0 Answers

Active LIve LIghting 0 Answers

How can I make lighting in scene shine at every part of objects 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