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 Draze · Jan 29, 2015 at 05:07 AM · spawningfile-iotiming

Set up spawn seqence based on specified timing

So I'm attempting to make a rhythm game in which enemies are spawned from certain locations based off of the song's rhythm. I know calculating the rhythm is a whole different subject, but let's pretend I have a set 'beat' calculated. How would I go about spawning enemies according to that 'beat'? I currently have gameobjects set up as spawners and they spawn prefabs of enemies.

The most logical way I could think to do this and maintain the ability to 'craft' the level and spawnings is to create a file and read from the file on 'beat'.


E.G. File Contents: xxxxxTxxxLxxxxB

On a beat> one character is read from the file and that corresponds to what happens (x does nothing, T spawns prefab 1, etc.

File and Song are started at the same time (and the file length is predetermined to make sure there are enough 'beats' marked.


So I guess my question is: Is this a 'good' way to go about this? And how exactly could I accomplish sequentially reading characters based on a timer of some sort?

Comment
Add comment · Show 3
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 yashpal · Jan 29, 2015 at 05:46 AM 1
Share

@Draze, I don't know the is your method is proper or not. but you can read file contain at specific interval by using InvokeRepeating. this call the function at regular interval. you can put there your reading file code.

avatar image Draze · Jan 29, 2015 at 07:50 AM 0
Share

I've seen similar things to that, as far as my idea for implementation however, I think I would run into the problem of reading the next character each time. I guess I could do a global variable to keep track of where I am and try and set end parameters for that repeating to stop. Good suggestion, I'll look into it more.

avatar image yashpal · Jan 29, 2015 at 08:44 AM 0
Share

@Draze, you can make an array or list which contains your levels information(like xxxxxTxxxLxxxxB so, levelData[0] = x, levelData[1] = x levelData[5] = T,...) and just store it's index what is last one. and this array can be store in file and get it back when you use it.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Naphier · Jan 29, 2015 at 10:41 AM

That's not a bad way to store it. There's so many ways this could be done. You could set up arrays to hold the spawn/beat data too. I like to use CSV files a bit for things like this so I can edit them in a spreadsheet, but there's no reason a simple text file wouldn't work. You have to balance: is it easier to write a function to parse the file data into an array for use OR is it easier to write out the arrays and have a function that retrieves the arrays. I do something similar in one of our games for the level data (CSV -> parsing function -> struct array).

Now you have everything in an array just set up a timer variable that gets activated on beat and keep track of the array's index.

Psuedo code

 Onstart - float spawnTimer = Time.time;
 
 OnUpdate
     if beat and (Time.time - spawnTimer > minTimeBetweenSpawns) {
         Spawn(arrayIndex);
         arrayIndex++;
         spawnTimer = Time.time;

I do something similar for animating sprites in our game that is using beat detection. http://u3d.as/8c6 is inexpensive and works well. I've yet to figure out how to determine the volume/amplitude of the beats, but I've not spent much time on it either.

Hope this helps.

Comment
Add comment · 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

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

21 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

Related Questions

NPCs falling through terrain 1 Answer

How to make my character change his location when he collides with an object 1 Answer

Spawn prefabs in a circle? 3 Answers

Spawning zombie when other zombie is killed 1 Answer

A Simple Spawning System Code. 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