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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by mwolff282 · May 20, 2013 at 08:11 PM · javascriptarrayactivegame object

Javascript How to Activate/Deactivate GameObject Arrays

I am currently trying to activate an array of game objects that I have assigned in Unity. I have a very simple script that doesn't do all that I want it to do, however I'm hoping that with this I can learn how to work with arrays. All I want to do is activate the objects in this array.

pragma strict

ar values : GameObject[];

function Start () {

//I want to declare that it is active here

}

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 KiraSensei · May 20, 2013 at 09:18 PM 0
Share

ExTheSea told everything. You cannot activate or deactivate the whole array with one command, you need to loop on all of them.

avatar image Benproductions1 · May 21, 2013 at 12:06 AM 0
Share

@ExTheSea, please convert your comment to an answer, so it can be marked as correct :)

avatar image ExTheSea · May 23, 2013 at 07:44 PM 0
Share

Is your probelm now solved? If so please accept the answer to mark the question as solved.

1 Reply

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

Answer by ExTheSea · May 20, 2013 at 08:15 PM

you should just go through the Array with a for-loop and then activate the gameobjects in the array:

 var values : GameObject[];
 
 function Start () {
 
 for(var i = 0;i<values.Length;i++){
   values[i].SetActive(true);
 }
 
 }
Comment
Add comment · Show 7 · 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 Eric5h5 · May 21, 2013 at 04:14 PM 1
Share

You need to use SetActive(true) actually; the .active variable is deprecated.

avatar image ExTheSea · May 21, 2013 at 04:16 PM 0
Share

Right, Eric5h5 although i think it's still working as i think i once tried it before i posted this answer but i could be mistaken.

avatar image Eric5h5 · May 21, 2013 at 04:27 PM 1
Share

It will still work at the moment, but it's a good idea to get in the habit of SetActive now because the old method won't keep working forever, and you don't want to have to go back and fix code.

avatar image ExTheSea · May 21, 2013 at 05:24 PM 0
Share

Your so right. Removing deprecated methods out of your code as soon as soon as they get deprecated is a really good idea. I just didn't know yet that gameobject.active is deprecated as i converted my project just recently. I also edited my answer for future reference.

avatar image Benproductions1 · May 21, 2013 at 11:22 PM 0
Share

@ExTheSea It's only a good idea if you can get the same behaviour some other way, without using the depricated method. This (afaik) does not apply to Input.eat$$anonymous$$eyPressOnTextFieldFocus. Even though it's depricated, there is no other way of getting the same behavious... :(

Show more comments

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

17 People are following this question.

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

Related Questions

How do i check if all tagged objects are inactive? 2 Answers

Increasing And Decreasing An Array Through A Variable 2 Answers

I need help with an array 1 Answer

Search a substring in an array of Strings 1 Answer

How to create dynamic array of type GameObject using javascript? 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