• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Related Questions

NullRerenceException On comparisons 0 Answers

Controlling One of Several Similar Playing Pieces 1 Answer

Classes and Scripting 2 Answers

Modifying a prototype in UnityScript 2 Answers

Does anyone know of good tutorials for learning arrays and classes? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges