• 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 CleeDotExe · Oct 05, 2021 at 08:23 PM · unity 2d

Filling array with GameObjects, but the gameobjects are children so it does not work.

Hi! This is my first question, ever, and it's about a code I've written that finds available transforms and saves them in one array, this does work, I've only run into a problem that I don't have a specified GameObject I'm working it out of, and I need the transforms of the children of the object (or multiple). What I'm trying to do is make a pipe generating system that makes random pipes instantiate at a suitable location at whatever space is available. Here's my code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using System.Linq;

 public class PipeSpawner : MonoBehaviour
 {
   // array for later on so I can choose which prefab is instantiated, so I know that E.G. a vertical 
   pipe would "Connect" to a top or bottom transform, I'm not using this yet.
   public GameObject[] HasTop;
   public GameObject[] HasBottom;
   public GameObject[] HasRight;
   public GameObject[] HasLeft;
   
   GameObject[] HasTopTrans;
   GameObject[] HasBottomTrans;
   GameObject[] HasRightTrans;
   GameObject[] HasLeftTrans;
   public GameObject[] Arrrr;
   
   

   public void OnClick()
   {
       HasTopTrans = GameObject.FindGameObjectsWithTag("Up");
       HasBottomTrans = GameObject.FindGameObjectsWithTag("Down");
       HasRightTrans = GameObject.FindGameObjectsWithTag("Right");
       HasLeftTrans = GameObject.FindGameObjectsWithTag("Left"); 
       Arrrr = HasTopTrans.Concat(HasBottomTrans).ToArray();
       Arrrr = Arrrr.Concat(HasRightTrans).ToArray();
       Arrrr = Arrrr.Concat(HasLeftTrans).ToArray();
       //this finds the objects with tag, which are just empty objects with transforms, and combines 
       them into one single long array so I can randomise which I choose.

   }
 }

I have not tried to get the transforms out of children of specified GameObject because that would only get 2 to 4 transforms of one pipe.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

134 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

Related Questions

Animator Always resets childobject active state to original 0 Answers

Random files from my game folder are gone for no reason 0 Answers

Using VSCode for Unity - Project loading failed 0 Answers

how do I find out which object is closer to the finish line? 2 Answers

My player does not jump on every click and if it jumps it is really short 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