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 Danne85 · Sep 04, 2018 at 08:42 PM · classesnumberstrings

Store strings in a number?

I want to spawn a gameobject at x seconds after game begins. For this I want the time to be random so I use x = Random.Range(0,endOfTheDay);... I also want this to contain information about the gameobject. Like name, age etc.. But I need the name to be printed before the spawn happens!

So it will be: at time x a character will be spawned with name "Alfred" age:25

There will be many more characters that will be spawned so how do I assign "Alfred" and 25 to the time x? Can I use a class for the time x somehow?

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

2 Replies

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

Answer by JVene · Sep 04, 2018 at 08:54 PM

After a second reading of your post, what you've described is a queue of work. It's just a list (perhaps List) of classes that contain name, age and time in seconds. This works best if the list is sorted by time in seconds, so it is in the order you intend to create the characters.


Each cycle (Update) you check the next (initially first) entry in the least (which should be the next character to spawn at some point in the future). If that time is matched (or expired), you can print the name (at any time before spawning), spawn, then move a 'counter' forward to the next entry in the list, and let it move the 'check' at the beginning of the next paragraph wait until that time expires, continuing to the end of the list.


I sense you're quite new, possibly a young student. I'm posting pseudo code to illustrate (it's untested example, not checked, likely valid code with no guarantee it doesn't need minor fixes or adaptation to your exact situation).

 public class Character
 {
  public float TimeToSpawn;
  public string Name;
  public float Age;
 }
 
 ....in some other class that 'owns' a list of these
 
 List< Character > characterList = new List< Character >();

Look into the List documentation for how to add to the list, sort it (if you require), and get entries from it. Further, you might prefer long or integer for age and time to spawn, up to you.

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
avatar image
0

Answer by Bunny83 · Sep 04, 2018 at 09:17 PM

I've once created a simple enemy wave spawning system over here. It's just a very simply setup and each wave action simply spawns a certain amount of enemies of a certain type. The waves can be setup in the inspector. Of course if you need other kind of actions to take place you have to account for those as well. For example if you only want to proceed to the next wave when all enemies of the current wave have been killed you have to do that yourself.


Your description of your question is very abstract so we can't get into any details if we don't know the exact behaviour you want. From the vague description i guess you don't even know what you actually want. So i suggest to think about your actual goals and requirements and write it down somewhere. Writing game design documents has several benefits. First of all you make yourself clear what you need. In addition it's the first step for documenting your software.

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

90 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

NullRerenceException On comparisons 0 Answers

Abstracting class vars, accessing vars by variable 0 Answers

How to reassign a variable's class 1 Answer

class inheriting Vector3 without using monobehavior? 1 Answer

C# Class and Array 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