Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Sangar · Mar 22, 2014 at 12:03 AM · arrayspawnlooppooling

Creating a looping spawn with an Array

Hi Guys,

I mention this on a previous thread briefly, but thought it would better to make a new thread as it is a different question. I am currently creating a game that has cubes moving in a sequential order. When the first cube gets to a certain location (e.g. x = 40 or fourth cube on the floor) then it should be moved off screen into a "pool" and added to an array called pool. Each time a cube is added to the array, a random one (already in the array) should be removed and moved to the starting position in the "queue" of cubes on scene. A screenshot shown below should help explain this a little clearer. I have chosen to move the cube to pools and use arrays, as opposed to instantiating a cube each time as it performance of the game would decrease substantially.

I currently have two scripts I am using: BuildingController (attached to each building to move them along) and Controller (handle the arrays).

BuildingController:

void Start ()

 {

     startingPosition = gameObject.transform.position;
 }
 void Update ()

 {

     if ((gameObject.transform.position.x >= 25)){

         gameObject.transform.position = pool1;

         //gameObject.transform.position = begin;
     } else {

         Move();
     }

 }
 void Move (){

     float translation = Time.deltaTime * 2;

     transform.Translate (0, 0, translation);

     transform.Translate (Vector3.forward * translation);

}

and the Controller script which is meant to supply the arrays and possible queue.

I cannot figure out the way to get this spawn loop working and how the two scripts can link into one another. alt text

If somebody could help me, it would be very much appreciated!

As a side note, I cannot use pool managers or the like downloaded from the asset store.

Many thanks

screen shot 2014-03-21 at 22.36.26.png (49.7 kB)
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 highpockets · Mar 22, 2014 at 06:33 AM 0
Share

If you want the cubes to be in an array on one script, you need to make an array of game objects on that script called pool. You can give values to the array by using a for loop and iterating through each object in the array in the start function.

To access that array from the other script, the other script will need a declaration of the class and you can use GetComponent to store it:

 private buildingController = BuildingController;
 
 void Start ()
 {
 
 //set buildingController to the proper instance
 buildingController = find.GameObject("BuildingControllerObjectName").GetComponent<BuildingController>();
 }
 
 void Update()
 {
 
 //access your array like so
 buildingController.pool(1).transform.position = new Vector3( 1,5,6 );
 }
avatar image Benproductions1 · Mar 22, 2014 at 07:13 AM 0
Share

@highpockets I don't think you can call an array (or list/`ArrayList`) ;)

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

22 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

Related Questions

set level to be played only 3 times 1 Answer

No Movement when Attempting to Lerp through an array 2 Answers

Making an Array of Spawnpoints... 1 Answer

Grabbing an object from array 0 Answers

Add object into an array without continuously adding it or looping. 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