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 sludgybeast · Oct 04, 2014 at 01:38 PM · javascriptgamerpg

using inheritance for multiple attacks

I was wondering if I can use inheritance to create multiple attacks easily. Here is what I mean

Base Class public class ShootingAttack extends MonoBehaviour{

 public var Target : Vector3;
 public var HitParticle = "";
 public var ShootParticle = "";
 public var ParticleS = "";
 public var Part_number : int = 1;
 public var Damage : int = 1;
 public var gravity : int = 0;
 public var Cooldown : int = 5;
 public var Move;
 public var timer;
 
 public function Start () {
            //start
     }
 }
 
 public function Update () {
 
 }
 
 public function PlayerAttack(){
    // attack
 }

and this would be inherited.

 class Ember extends ShootingAttack {
         
     public function start(){
         super.HitParticle = "FireAt";
         ShootParticle = "FireAt";
         ParticleS = "Attack";
         Part_number  = 1;
         Damage  = 5;
         gravity = 0;
         Cooldown = 5;
     }
 }

and pretty much the base class would use the inherited values to attack so I can quickly create multiple attaks by changing values.

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 fafase · Oct 04, 2014 at 01:43 PM

You are misunderstanding the purpose of inheritance. In your case, what you want is different prefab on which you add the base class and pass the values in the inspector. Then each prefab is a ShootingAttack but with different skills and attributes. (Also it is Start and not start).

The purpose of inheritance is that you would create different type of ShootingAttack (like you are now) but some would have different behaviour though still being a ShootingAttack. For instance, you have a ShootingAttack that explodes and another that gets stuck to the target (arrow). Those two would have some common behaviours and variables like the fact they move like a projectile, have damage value and so on. But the on impact, they act different so you would sub class and implement differently.

As long as it is just a matter of values, use prefab only.

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

2 People are following this question.

avatar image avatar image

Related Questions

Does Anyone Have a Halo-Like Scripts? 1 Answer

I need help fixing this code 1 Answer

Already has a definiton for 1 Answer

Creation of RPG Class Stat Presets? 1 Answer

What is better for a game character? 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