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 /
  • Help Room /
avatar image
0
Question by HNKMaster · Apr 05, 2016 at 06:35 PM · listattackmethods

Trying to do a list of attacks for a Beat em Up.

Hi.

I'm doing a Beat'em Up, and while I did the movement and IA for enemies, I have trouble doing the attack part. What I mean is, I have the characters hit the player when the conditions met, but I have issues related the multiple attacks an enemy can do. I did an "EnemyAttackList" script:

 using UnityEngine;
 using System.Collections;
 
 public class EnemyAttackList : MonoBehaviour {
 
     private Animator anim;
     private EnemyActions actionScript;
 
     public int[] comboList;
 
     // Use this for initialization
     void Awake () {
         actionScript = GetComponent<EnemyActions>();
         anim = transform.FindChild("Char").GetComponent<Animator>();
     }
 
     void Start () {
 
     }
 
     public void BasicPunch1()
     {
         actionScript.damage = 5;
         actionScript.canLaunch = false;
         actionScript.hitPosition = 1;
         anim.SetInteger("ATK_INT",  comboList[0]);
     }
 
     public void BasicPunch2()
     {
         actionScript.damage = 5;
         actionScript.canLaunch = false;
         actionScript.hitPosition = -1;
         anim.SetInteger("ATK_INT",  comboList[1]);
     }
 
     public void Kick()
     {
         actionScript.damage = 10;
         actionScript.canLaunch = true;
         actionScript.hitPosition = -1;
         anim.SetInteger("ATK_INT",  comboList[2]);
     }
 
     public void JumpKick ()
     {
         actionScript.damage = 10;
         actionScript.canLaunch = true;
         actionScript.hitPosition = 1;
         anim.SetInteger("ATK_INT",  comboList[3]);
     }
 
     // Update is called once per frame
     void Update () {
     
     }
 }
 

With it, I want to do specific scripts for each enemy using EnemyAttackList as class. Attacks are linked to the animation (it manages the hitbox and sets the end of the attack). But my problem is, I want to "store" those methods on a kind of list from another script, so they became easier to access.

Can anyone help me solve it please? Thanks

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 coolraiman · Apr 05, 2016 at 07:11 PM

use a struct instead with all the stats data

load the stats data from a xml into a struct array so you wont even have to touch your code to change, add or remove attacks

then make a function called attack taking the struct or the array index of the attack.

your code will be cleaner

the second option would be to use delegate but i dont really suggest that approach for that case.

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 HNKMaster · Apr 06, 2016 at 02:41 AM 0
Share

I made this struct:

 public struct AttackStats
 {
     public string name;
     public int damage;
     public bool canLaunch;
     public int hitPosition;
 }

But I'm not familiarized with both struct and the use of X$$anonymous$$L on Unity, and I don't know how can I access and set values with them :(.

avatar image coolraiman HNKMaster · Apr 06, 2016 at 12:57 PM 0
Share

for the sake of simplicity and learning.

create an array of that struct by code also add a constructor in it. A struct constructor force you to assign a value to each variable this will make sure that each variable have a value

avatar image HNKMaster coolraiman · Apr 06, 2016 at 03:40 PM 0
Share

I did something that didn't allowed me to edit my structs, but I fixed it using [System.Serializable] and now it works. Thanks a lot!

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

40 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

Related Questions

How to make list of methods (example Sims) 1 Answer

Check if a large number of gameobjects are colliding 1 Answer

Random Teleport Character issue...Help Please. 1 Answer

Arbitrary line in one method prevents another for working? 1 Answer

I can't seem to have access to Tilemap methods, what am I doing wrong ? 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