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 Jun 13, 2018 at 07:56 AM by ludwu for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by ludwu · Jun 09, 2018 at 09:35 PM · gameobjectinstantiatelistremoveat

Destroy a gameobject from an index of a list, destroy all same gameobjects right after it, why ?

Hi there ! Here is my configuration : I got an array of 7 prefabs. I instantiate continually and randomly gameobjects from this array and add it on a list. 7 buttons from the pad controller are configured to destroy the gameobjects. For now, my script work well : gameobjects runs in the scene, from right to left. If I put one of the buttons it destroy the first instantiated gameobject (due to the list index). But what I don't understand is why, when 2 or more same gameobjects are next to each other's, the button destroy all those same gameobjects.

Here is the code :

 if (Input.GetButton("yButton"))
             {
                 if (NoteList[0] == Bnote)
                     {
                     Destroy (NoteList[0].gameObject);
                     NoteList.RemoveAt(0);
                     }


In my point of view, NoteList[0].gameObject, shouldnt destroy NoteList[1/2/3/...].gameObject, nope ?

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

  • Sort: 
avatar image
1
Best Answer

Answer by Irrgeist · Jun 10, 2018 at 01:43 AM

Try using Input.GetButtonDown("key") instead of GetButton.

As the documentation states (https://docs.unity3d.com/ScriptReference/Input.GetButtonDown.html):

Returns true during the frame the user pressed down the virtual button identified by buttonName.

  1. GetButton probably fires multiple times each frame. You have to press the button really fast, since GetButton always returns true while the button is pressed. Since there are a lot of frames processed each second, more objects get deleted.

  2. GetButtonDown fires only in one frame and also:

    It will not return true until the user has released the key and pressed it again.

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

Answer by ludwu · Jun 10, 2018 at 09:21 AM

Yeah saw my misstake yesterday thank you so much ! But now got the same problem with d pad I use like buttons. Tried many things to make it work like buttons down but nothing work... Any ideas ?

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 ludwu · Jun 10, 2018 at 05:29 PM 0
Share

Finally found the way, below is the code for vertical axis :

 private bool v_isAxisInUse = false;
 
 if (Input.GetAxisRaw("dpadAxisV") > 0)
             {
                 if (v_isAxisInUse == false)
                 {
                     if (NotesList[0] == Dnote)
                         {
                         Destroy (NotesList[0].gameObject);
                         NotesList.RemoveAt(0);
                         }
                 v_isAxisInUse = true;
                 }
             }
             if (Input.GetAxisRaw("dpadAxisV") < 0)
             {
                 if (v_isAxisInUse == false)
                 {
                     if (NotesList[0] == Fnote)
                         {
                         Destroy (NotesList[0].gameObject);
                         NotesList.RemoveAt(0);
                         }
                 v_isAxisInUse = true;
                 }
             }
             if (Input.GetAxisRaw("dpadAxisV") == 0)
             {
             v_isAxisInUse = false;
             }

Do the same for horizontal axis with a private bool v_isAxisInUse = false;

Follow this Question

Answers Answers and Comments

142 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 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

Instantiate an object and place it on a list. 1 Answer

Destroy and rebuild game objects from lists 1 Answer

A node in a childnode? 1 Answer

Instantiate prefab and Add to a Generic List 2 Answers

How to put gameObjects to the list? 4 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