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 cj31387 · Oct 12, 2012 at 10:16 PM · transformarray

Array of Transforms with variable

I currently have AI that goes to formation slots, Right now they are hard set but I need them to figure out which spawn socket is free out of many of them (right now if 2 formations are in the scene they will only go to one formation). For instance I have a prefab called 4 slot formation, later on I'm going to randomly spawn these formations around the map, and my enemies go to the sockets inside these formations. Here is the code I have so far but its set to go to specific formations, I need it to be more dynamic.

 Fighter_AI.cs
 
 // Moves the ships to the right spots. May need to replace the target with a variable that gets adjusted by how many formations are added
     void GoToSlot01()
     {
         transform.position = Vector3.Lerp(transform.position, FormTarg1.position, Time.deltaTime * smoothTranslateSpeed);
     }
 
     void GoToSlot02()
     {
         transform.position = Vector3.Lerp(transform.position, FormTarg2.position, Time.deltaTime * smoothTranslateSpeed);
     }
 
     void GoToSlot03()
     {
         transform.position = Vector3.Lerp(transform.position, FormTarg3.position, Time.deltaTime * smoothTranslateSpeed);
     }

What I need to know how to do is set up a array of transforms that checks all the formations prefabs child spawn sockets and maybe turn that into a temp variable so after one fighter goes to 1 slot it then goes to the next transform. I've already asked the first part of this question on just reserving slots for the enemies but I don't know how to send them to each of the slots transform dynamically (they only go to 1 formation if 2 or more formations are in the scene). The other question is here.

http://answers.unity3d.com/questions/330696/unique-prefabs.html

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 sparkzbarca · Oct 13, 2012 at 07:47 AM

 script attached to spawn prefab


 public int formation size = 4 // must be public so you can see if a formation needs filled

 bool[formation_size] fighters;
 vector3[formation_size] FormTargets;
 on start 
 iterate through fighter setting each to zero
 
 foreach (transform child in transform)
 {
 
    foreach (bool plane in fighters}
     {
       position_iter++;
       if(!plane)
          { 
            transform.position = Vector3.Lerp(transform.position, FormTargets[position_iter].position, Time.deltaTime * smoothTranslateSpeed);
           }
     }
 }

now all you have to do is set the fighters parent equal to the nearest formation with formation.transform.childcount < formation.formation_size;

 fighter script
 all_formations = FindObjectsOfType<formations>;
 
 foreach (formations formation in all_formation)
 {
     if(formation.transform.childcount < formation.formation_size)
      { 
         transform.parent = formation; //parent this fighter to that formation
      }
 }

took me a few minutes so mark answered if its answered and let me know if you need a little more help implementing. :P

Comment
Add comment · Show 2 · 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 cj31387 · Oct 13, 2012 at 09:16 AM 0
Share

Thanks that looks like it will work. Idk why but I usually post all day and don't get a answer till bed time. I'm pretty tired right now, I'll try this asap when I wake up. Do you $$anonymous$$d if I pm you if I run into trouble tomorrow?

avatar image cj31387 · Oct 14, 2012 at 12:45 AM 0
Share

I don't know how to implement that.

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

10 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

Related Questions

Sorting an Transforms array by gameobject name 1 Answer

problem moving a prefab object in script (c#) 0 Answers

Unity3D - Playback object array of position (with dynamic velocity) 0 Answers

Getting radius around multiple transform 1 Answer

Undeclared transform array 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