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 /
  • Help Room /
avatar image
0
Question by captainfrogduh · Jan 30, 2017 at 11:33 AM · arrayunity5spritesgameobjectslists

Trying to get gameobject from one list to follow gameobjects in another list

I have 3 instances of a single gameobject (hollow bubbles) which im moving around in my game screen. That has been successfully achieved but now im trying to create 3 another instances of gameobject (the inner bubbles) which follow the first 3 instances of hollow bubbles.

I have created 2 Lists which hold these 3 instances respectively and an array that holds in Element 0 the sprite that i need to add to the inner bubbles that follow the hollow bubbles.

 public Sprite[] innerBubblesSprites;
 
 private List<GameObject> yellowBubbles = new List<GameObject>();
 private List<GameObject> innerYellowBubbles = new List<GameObject>();
 
 void GameLogic() {
 for (int j = 0; j < 3; j++) {
         if (i == 0) {
             Vector2 yellowPos = new Vector2 (Random.Range (-2.5f, 2.5f), -9.8f);
             yellowBubbles.Add(Instantiate(bubbles[i], yellowPos, Quaternion.identity) as GameObject);
             yellowBubbles[i].transform.localScale = new Vector2 (bubblesScale, bubblesScale);
             StartCoroutine ("BlinkingBubbles");
     }
 }

 IEnumerator BlinkingBubbles() {
     for (int i = 0; i < 3; i++) {
         innerYellowBubbles[i] = Instantiate (innerBubblesGameObjects [0], yellowBubbles [i].transform.position, Quaternion.identity) as GameObject;
         innerYellowBubbles[i].GetComponent<SpriteRenderer> ().sprite = innerBubblesSprites [0];
         yield return null;
         }
     }


The 3 instances of innerYellowBubbles are spawning fine in the object hierarchy but all seem to be spawning at the same position and the sprite is also not getting assigned. Further only the first yellowBubble is getting its localScale to the values ive set, otherwise they revert to their default scaling of 1.0. And there is an argument out of range exception. Can somebody please point me in the right direction? Any help would be appreciated. Next ive to make the innerYellowBubbles follow the YellowBubbles as well.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by captainfrogduh · Jan 31, 2017 at 12:01 PM

Looks like i was using Coroutines in a way that they are not meant to. Solved this problem. Heres a great explanation of using Coroutines for not so 'technical' (newbie) programmers :)

http://answers.unity3d.com/questions/276055/question-about-coroutines-and-waiting-for-a-functi.html

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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Trying to program two buttons to appear when the player in my game dies 0 Answers

Certain animation states not playing on mobile. Not sure if it's my code or a bug. 0 Answers

Cycling through array not working. Pulling my hair over this one. 0 Answers

List resulting in out of range 0 Answers

Unity won't print last item in my array for my GameObjects 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