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 kot2202 · Jul 09, 2020 at 01:55 PM · aienemyenemy aienemiesenemy damage

Different enemy types script design

So I have 2 different enemy types for now. Both of them with EnemyAi, Health scripts tied to parent and EnemyAttack script tied to child damage zone trigger.

Currently the enemies are all melee and just have different damage and attack delay from EnemyAttack.cs. I wanted to add some abilities for the enemies so they may for example stun, slow you on attack; some may also have occasional projectile shooting towards the player; some may charge at the player. So where would it make sense I add the scripts for that? I had an idea of using enum on enemyAi, so EnemyAttack will use switch with the enum enemy type on attack method but I want to hear your opinions. Maybe separate script for each special ability would be good?

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
1
Best Answer

Answer by hacky97 · Jul 09, 2020 at 02:35 PM

a separate script for each ability will be very good. Let the scripts all inherit from a generic attack class, so you can add that class to the player:

 public class stun: attack
 {
 
 }

Comment
Add comment · Show 4 · 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 kot2202 · Jul 09, 2020 at 06:37 PM 0
Share

I saw few suggestions about inheritance over the internet, but I'm not sure... what would it allow me to do? Would it make me remove EnemyAttack script from enemy because I could use Stun class with EnemyAttack's methods ins$$anonymous$$d? Is that how it works? I don't really get inheritance and I don't think it would work well with my player's attack because it uses different non melee loadout with switching weapons system

avatar image hacky97 · Jul 10, 2020 at 11:50 AM 1
Share

@kot2202 It would allow you get rid of the enum and have each decendent of attack handle its own code. In the beginning it will be more of a hassel, later, ehwn enemies can attack more than only the player and when the attacks types become more, you will be happy to have inheritance. It can be a bit hard to wrap your head around. Look at this video and try it with some basic classes first: https://www.youtube.com/watch?v=F7Wu6_uzD1I

avatar image kot2202 hacky97 · Jul 10, 2020 at 06:27 PM 0
Share

So I understood it this way - I will recreate EnemyAttack.cs script into separate classes, because now it not only did the attacking but also trigger enter, exit detecting.

  • I will create separate detection script that calls [SerializeField] UnityEvent on triggers and I will attach the new 'special type attacking' script to the event. The special attacking script will inherit from basic attack script that all it does is deduct enemy hp + do some extra thing like stun on top of that from the special type attack script.

Is it correct solution? Events came to my $$anonymous$$d because I have no idea how would I access the different scripts of attack types, I wouldn't want to check 10 GetComponents, I have never used events before though

avatar image hacky97 kot2202 · Jul 13, 2020 at 07:50 AM 1
Share

Yes, that sounds like the right way to go. I would have multiple special attack scripts like AttackStun, AttackSlow or AttackProjectile.

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

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

Kill character on impact 1 Answer

Why do the AI get caught on trees? 0 Answers

NavMeshAgent does not follow player 0 Answers

free roaming enemy ai 1 Answer

Enemy walking off platform in 2D mode 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