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 /
avatar image
0
Question by ohkayem · May 18, 2018 at 05:41 PM · listliststogglearray of gameobjects

Toggle Menu Not Working

Dear Coders Can anyone help? I have created a scrolling menu which allows me to add one of two sprites to the transform of an empty gameobject.

On scene loading, the first sprite (Index 0) appears. If I implement buyCharacter, it adds it to my existing empty gameObject. However, I cannot then scroll through to the next character.

However, on scene loading if I toggle right to the second sprite, I can implement buyCharacter and the sprite will be added to my empty game object after which I can then toggle left to the first sprite.

Would anyone have any suggestions as to how I would be able to add either sprite and 'buy' it and still be able to access the other?

Thankyou in advance!

public List chooseSprite;

     public int index;
 
     public GameObject characterSelector;
     public GameObject currentSprite; 
 
     [HideInInspector] public PickPlayer pPlayer; 
     [HideInInspector] public List <GameObject> pPlayerList; 
 
     public void Start ()
     {
      
         List <GameObject> chooseSprite = new List<GameObject> (); 
 
         for (int i = 0; i < chooseSprite.Count; i++) {
             if (chooseSprite [index]) {
                 chooseSprite [index].SetActive (true); 
             }
         }
 
 
     public void  Update (){
 
         currentSprite = chooseSprite [index]; 
 
         if(Input.GetKeyDown(KeyCode.A)){
             buyCharacter(); 
         }
     }
 
     public void ToggleLeft(){
         chooseSprite [index].SetActive (false); 
         index--;
 
         if (index < 0)
             index = chooseSprite.Count - 1;
 
         chooseSprite [index].SetActive (true);
 
     }
 
     public void ToggleRight ()
     {
         chooseSprite [index].SetActive (false); 
         index++;
         if (index == chooseSprite.Count)
             index = 0;
 
         chooseSprite [index].SetActive (true); 
     }
 
     public void buyCharacter (){
 
         for (int i = 0; i < chooseSprite.Count; i++) {
 
             chooseSprite.Remove (currentSprite);
             FindObjectOfType<SkinAdding> ().AddPlayer ();
             index++; 
             if (index == chooseSprite.Count)
                 index = 0;
         }
     }
 
 
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

0 Replies

· Add your reply
  • Sort: 

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

84 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

Related Questions

List of bools assigned to each Gameobject in List/Array 0 Answers

A node in a childnode? 1 Answer

How to add an item to a list with a class/uJS struct? 1 Answer

multi dimensional array of lists 1 Answer

In a group of gameobjects, how to have only one object active at a time while disabling the others? 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