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 Shiro_Rin · Sep 15, 2015 at 05:38 PM · c#scripting problemtransform

Add transforms to Transform[] list at runtime

Essentially my game is a game where enemies have spawn points based on a Transform[] list. Well you have multiple paths you can take, so my old way of just replacing the list with every door no longer works. Is there a way I can add Transforms to this current list ? Example would be

Script 1 public Transform[] spawnPoints; public float SpawnTime; public GameObject Enemy; void Start(){

         InvokeRepeating ("Spawn", SpawnTime, SpawnTime);
     }
 
     void Spawn ()
     {
         int spawnPointIndex = Random.Range (0, spawnPoints.Length);
                 Instantiate (enemy, spawnPoints [spawnPointIndex].position, spawnPoints [spawnPointIndex].rotation);
     }


and Script 2 would have to work in a way that I can add to the list SpawnPoints. It's not as simple as

 public Transform[] AddPoints;
 
 
 public void AddSpawnPoints(){
 SpawnPoints+=AddPoints;
 }

I tried it in hopes , even tho I knew it wouldn't. So any help ?

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
3
Best Answer

Answer by Jessespike · Sep 15, 2015 at 07:07 PM

Try a list instead:

  List<Transform> SpawnPoints;
  SpawnPoints.AddRange( AddPoints );
Comment
Add comment · Show 5 · 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 Shiro_Rin · Sep 15, 2015 at 07:08 PM 0
Share

I'll look into lists, never really used them before. I'll work it in and see how it goes. Thank you for the response

avatar image Jessespike · Sep 15, 2015 at 07:11 PM 0
Share

you'll need to include this to your script as well:

  using System.Collections.Generic;
avatar image Shiro_Rin · Sep 15, 2015 at 07:12 PM 0
Share

That explains why it was being weird lol. Saved me a search

avatar image Shiro_Rin · Sep 15, 2015 at 07:26 PM 0
Share

Would you happen to know what I would replace int spawnPointIndex = Random.Range (0, spawnPoints.Length); with ? Because Length isn't something I can use, so I tried Get Range and got an error about floats. Would Capacity work ?

avatar image Shiro_Rin · Sep 15, 2015 at 07:36 PM 0
Share

It works, thank you so much !!!!! Plus you introduced me to something awesome, as I've never known of Lists before. It's like a regular array but more flexible. Thank you

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

27 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

Related Questions

MoveTowards issue, animating ui. 1 Answer

Multiple Cars not working 1 Answer

Error CS0029: Cannot implicitly convert type to UnityEngine.UI.Transform 1 Answer

Tower defense target update 0 Answers

Transforming a GameObject with an unattached script 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