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 Dec 09, 2018 at 09:38 PM by dhritivasu for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by dhritivasu · Dec 08, 2018 at 07:20 PM · objecthidevisibilityshowappear

Objects Appearing

I have 36 objects in and I want them to appear one by one. The player should press a certain key on the keyboard and one object would show up. When it presses the same key, another object would show up and so on. Does anyone know how I would do that?

Comment
Add comment · Show 2
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 Vega4Life · Dec 08, 2018 at 08:25 PM 0
Share

Are they already created in the scene and the gameObjects are disabled (which makes them invisible), or you want them to literally spawn when a button is pressed?

avatar image dhritivasu Vega4Life · Dec 08, 2018 at 08:28 PM 0
Share

They are already created. I want them to not be visible and when you press the key, it would be visible

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by leftshoe18 · Dec 08, 2018 at 09:17 PM

You could put all of the objects into an array and disable them on game start and enable them again upon pressing a button.

Something like this:

 [SerializeField] GameObject[] objects;
 int index = 0;
 
 void Start()
 {
     foreach(GameObject go in objects)
         go.SetActive(false);
 }
 
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Space)) //change this to whatever you want for input
     {
         if (index < objects.Length) // to avoid indexing errors
             objects[index].SetActive(true);
         index += 1;
     }
 }

The index increments with each new object enabled so that it will enable the next one the next time you press space.

Comment
Add comment · Show 5 · 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 dhritivasu · Dec 08, 2018 at 11:22 PM 0
Share

Would I have to change anything in this function?

avatar image dhritivasu dhritivasu · Dec 08, 2018 at 11:24 PM 0
Share

Because my game objects are named things like A1, B3, ...

avatar image dhritivasu · Dec 08, 2018 at 11:27 PM 0
Share

Also, where would I put this script?

avatar image dhritivasu · Dec 08, 2018 at 11:56 PM 0
Share

Actually, I figured it out. Thank you so much for your help!!

avatar image leftshoe18 dhritivasu · Dec 09, 2018 at 03:12 AM 0
Share

No problem!

Sorry I didn't reply sooner. I was at work. lol

Follow this Question

Answers Answers and Comments

103 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 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 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 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 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 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 avatar image

Related Questions

Object Visibility 2 Answers

Hide Object in Editor Only 5 Answers

Unity 2019.4.9f1 - Toggle Show/Hide Gameobject with one keystroke. 1 Answer

on collision, show/hide other model scripting ? 1 Answer

Look at Object 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