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 MonKcz · Feb 13, 2014 at 09:04 PM · classgameobjectsspawningtower-defenseunits

Class for spawning units (gameobjects)

Hey guys, I am not sure if someone asked before about this but I didnt find it so...

We are creating a TD game with my classmate and I dont really know how to make several types of units ( with different hp, gold reward, special abilities, ...). I created spawning system with certain amount of units and interval of spawning plus prefab of gameobject in one script and its all working. But the thing is I cant figure it out how to create class of units where will be every attribute that i can later connect to prefabs of every unit and connect it to spawning system as well. I mean like tower shoot and hit one gameobject and the hp of the unit will decrease.

So if you get it please help me. :)

Best regards, MonK

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 Fr0stbite · Feb 13, 2014 at 09:10 PM 0
Share

Do u mean?:

 public class $$anonymous$$yUnity {
 var hp : float;
 var gold : float;
 var reward : float
 var specialAbilites : String;
 
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by VesuvianPrime · Feb 13, 2014 at 10:43 PM

Hi MonKcz

If I understand what you're saying, you want to register new units with scripts that are responsible for interacting with them. So for example, a Tower needs to be aware of it's targets even though they may not be immediately related.

This is a tricky subject, and there are a couple ways of solve it. My personal approach so far has been to use a singleton, but singletons are a fairly polarizing subject among programmers so don't be surprised if I get criticised for this post.

Firstly, the wiki singleton implementation: http://wiki.unity3d.com/index.php/Singleton

Using this Singleton MonoBehaviour I would make a Singleton UnitSpawner:

 public class UnitSpawner : Singleton<UnitSpawner>
 {
 }

Now, from here any of your scripts will be able to access the UnitSpawner by using UnitSpawner.Instance.

You could have a property that stores all of the instantiated units so all of the towers have a quick reference to the units.

I would suggest playing with this and seeing what you can do. It's a fairly inelegant solution, but it should get you back on your feet for a bit.

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

20 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

Related Questions

Spawn GameObject Above and Below GameObject 0 Answers

Correct way to spawn and move objects 1 Answer

extra GameObjects Spawning 2 Answers

Check if tower is already placed 1 Answer

GameObject Class understanding 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