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 Cristian · Mar 27, 2011 at 02:46 AM · randomspawnpoint

Find the respawn objects and randomly spawn in one?

How could i do this because they are created randomly from another script, so I wont know how many there is and I wont be able to set it into the array variable in the script.

So i think i am going to have to use the gameObject.FindGameObjectWithTag("Respawn")?

How could i do this? I am stumped and confused

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 Alec-Slayden · Mar 27, 2011 at 03:27 AM

You should be able to add each object as they're created to an array, even if you don't know how many there will be.

Just add the object to the array right after its creation.

If you wanted to do the find method, take a look at GameObject.FindGameObjectsWithTag() make sure the "G" is capitalized for that. That will create an array of game objects that you can access.

EDIT:

If I understand correctly, the main problem you're having is that you can't assign an array to a prefab that doesn't yet exist in game.

What you can do is assign the list of respawn points to a static variable in a different script, and then reference that.

When you spawn your object, it doesn't have to be in the respawn point right away. You can instantiate it anywhere, perhaps out of view to be safe, and then let its script decide what to do next, E.G. randomly determine which respawn point to move itself to, referencing the static array of respawn points that was generated earlier.

Comment
Add comment · Show 3 · 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 Cristian · Mar 27, 2011 at 03:29 AM 0
Share

The script that wants to respawn isnt activated till after.

avatar image Alec-Slayden · Mar 27, 2011 at 04:19 AM 0
Share

You can still set variables in scripts that are not enabled. You can even use functions in them. There should be no problem modifying the array then using it when the script is enabled.

If for some reason you're not able to use your preferred script to store the variable, you can always store it in a different script to be referenced later, perhaps a good time to create a script for global variables?

avatar image Alec-Slayden · Mar 27, 2011 at 04:43 AM 0
Share

ah I see, you have the script on the object to be spawned I take it?, editing the answer for this

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

No one has followed this question yet.

Related Questions

Spawn object in random areas 2 Answers

Spawning - How to only have one object at a spawn at a time? 0 Answers

Creating a light in game C# 1 Answer

Randomly Initiate Cubes - Prevent Same Position 0 Answers

Random Position 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