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 Bumpety93 · May 05, 2018 at 09:36 AM · instantiateprefabclassstorecharacters

How to create multiple Characters?

Hello,

I want to create multiple characters programmatically in a script. The Problem is, I can't find anything where or how do I store the Assets of this Character. Lets say, we have a script which is holding some items of the player. Another script is holding data about the player stats. But a player have also a model in the scene. My first idea was, to create the model and add the two scripts as the components. Then I have to store my characters in the script what is creating the characters as game objects. The problem is, that I only can access the components with the GetComponent() method. So I have to store the components as well or I have to call this Method a lot! My second idea was, to create a GameObject with the creation script und in this script I store the Characters in a List. Each character have a string with its model and own instances of items and stats.

What is the right way? Unity let me do quit everything.

Thanks a lot!

Comment
Add comment · Show 1
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 Pinkuboxu · May 05, 2018 at 04:47 PM 0
Share

I hope I'm not saying something you already know but you actually don't have to call GetComponent() in a lot of cases, though it's perfectly fine to use it. An alternative is if you make a variable public or put [SerializeField] next to it in a script, you get a box in the inspector on the script component that you can plop an instance onto to reference pretty much anything, including classes.


It kind of sounds like you are on the right track. I don't think there is a specific right way. The wrong way would be if your implementation didn't work at all or was impossible to refine, expand or build upon later. This is what we often do in prototype phase is just throw something together to get a working example and then fix it up later when we have a better idea of our needs.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Koyemsi · May 05, 2018 at 03:31 PM

I think I would organize the project this way :

  • Characters are prefabs with their own scripts.

  • Put a level manager in the scene (an empty GO + script). The script would centralize all infos about the level, like the number of enemies / characters, and maybe even the player's info if it's more convenient for you . It would spawn characters (instantiation), and give them the desired parameters (health, ammo and so on). A reference to the spawned characters should be kept in a List or Array for convenience.

Does this answer your question ?

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 marcelomb · May 05, 2018 at 04:24 PM

Maybe this helps you: Unity Training Curse

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

123 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 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

Instantiate Prefab from within class 2 Answers

Retrieving GameObjects from a Prefab 1 Answer

Need Help With 2D Array Grid Position Tracking With JavaScript 1 Answer

The object Player(Clone) must be a prefab in the project view. 1 Answer

Lobbing a Bomb with Instantiate. 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