Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by OctoMan · Feb 18, 2016 at 09:33 PM · editorlistclassinheritance

Define attacks to choose from

Hi,

i'm looking for a way to create an array or a list to choose a random attack from. The problem is that my attacks are derived classes and i currently don't know how to get the right infos. Since they don't derive Monobehavior i can't create prefabs.

Here is what i got so far:

The base class.

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class BaseAttack
 {
     public string AttackName;
     public int AttackID;
     public string AttackDescription;
     public float AttackDamage;
     public float AttackCost;//Mana cost for example
 }

and one of my attacks.

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class StandartAttack : BaseAttack 
 {
     public StandartAttack()
     {
         AttackName = "Normal Attack";
         AttackID = 1;
         AttackDescription = "Just the standart attack";
         AttackDamage = 10;
         AttackCost = 0;
     }
 }

I want to make use of differnt attacks, and set them by hand in the editor for each enemy i have to choose any attack from. Like a public List or Array. I hope you understand my problem. What step did i missed?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by UCSIM · Feb 18, 2016 at 10:37 PM

If I understand correctly you are looking to create a list of all attacks that includes any attack that inherits from BaseAttack.

Because StandartAttack inherits from BaseAttack you can create a list of BaseAttacks and then put StandartAttack object in it. As well as any different attack as long as they also inherit from BaseAttack

Example:

  List <BaseAttack> attacks = new List<BaseAttack>  

And then just add whatever attacks you want to the List.

Comment
Add comment · Show 3 · 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 OctoMan · Feb 18, 2016 at 11:00 PM 0
Share

Basicly you got me right, but id like to drag in the attacks a specific enemy can have into the inspector, in this list. Or how should i make right use of it?

avatar image OctoMan · Feb 18, 2016 at 11:27 PM 0
Share

I think i got an idea. If BaseAttack would inherit $$anonymous$$onobehavior i can drag each attack onto an empty game object, create a prefabof it and then drag those into the list. In the end i might have 100 prefabs of different attacks to choose from, and place those into the list of attacks possible to use. Wouldn't i lose the connection to them, once i reload the scene for example?

All my enemys also need to be a prefabs to deter$$anonymous$$e who to fight.

The question now is, is this the only way? Or a good way to do it?

avatar image UCSIM OctoMan · Feb 22, 2016 at 10:33 PM 0
Share

I wouldn't do that, but what you can do is make all of the attacks as scripts. Then you can drag those scripts onto each enemy. After doing that you can add them to a public list like mentioned above that you made on that enemy.

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

48 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

Related Questions

Suggestions for planning project tasks and organizing classes/functionality? 0 Answers

Custom Editor List with child classes 1 Answer

How do I get string from a list using get? (Java) 0 Answers

List object variable returning different results 1 Answer

Code only runs when object is selected in the editor 0 Answers


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