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 galloping_bull · Apr 20, 2015 at 03:40 AM · array2d gamemeleetop down shooter

Need help with my melee system and arrays

Hey guys,

I'm still fairly new to programming and this problem has been giving me a major headache. Hopefully one of you guys can help me out.

So I currently have a melee system working (using this guy's tutorials:https://www.youtube.com/watch?v=fxSM_INrmF8). The problem is that the weapon only focuses on one enemy of the same tag -- meaning it only inflicts damage to one instance of that enemy. Instead, I want it to do damage to multiple enemies of different tags (at most 3 tags) if they're in front of the player.

I know I'm going to have to implement a list, or array, to hold my enemies, but I'm not sure how. Any help would be great, thanks!

public class Melee : MonoBehaviour {

 public float lightAtkDmg, heavyAtkDmg; 
 public GameObject target;

 private float heavyDistance;
 private float lightDistance;
 private float deflectionDistance; 

 bool isAttacking = false; 


 // Use this for initialization
 void Start () {
      
     //target = 

 
 }
 
 // Update is called once per frame
 void Update () {
     Debug.DrawLine (target.transform.position, transform.position, Color.yellow);


 }



 public void heavyAttack(){
     isAttacking = true; 
     heavyDistance = Vector3.Distance (target.transform.position, transform.position); 
     Vector3 Dir = (target.transform.position - transform.position).normalized; 
     float Direction = Vector3.Dot (Dir, transform.forward); 
     Debug.Log (Direction); 
     Debug.Log (heavyDistance); 

     
     if (target.gameObject.tag == "Enemy" && heavyDistance < 3) {
         if(Direction>0){
             Debug.Log ("Hit Enemy_Charger w/Heavy");
             target.GetComponent<Entity> ().TakeDamage (heavyAtkDmg);
         }
     }

     
     if (target.gameObject.tag == "Destructible" && heavyDistance < 2) {
         if(Direction>0){
             Debug.Log ("Hit EDestructible w/Heavy");
             target.GetComponent<Entity> ().TakeDamage (heavyAtkDmg);
         }
     }


     if (target.gameObject.tag == "Magic" && heavyDistance < 2) {
         if (Direction >0 & heavyDistance >1.8){
             Debug.Log("magic deflected w/heavy");
         }
     } 
     isAttacking = false; 

 }

 public void lightAttack(){
     Debug.Log ("perform Light Attack");

     isAttacking = true; 
     Vector3 Dir = (target.transform.position - transform.position).normalized;
     float Direction = Vector3.Dot (Dir, transform.forward);
     lightDistance = Vector3.Distance (target.transform.position, transform.position); 
     Debug.Log ("Light Distance" + lightDistance); 
     //Debug.Log (Direction); 


     if (target.gameObject.tag == "Enemy" && lightDistance < 1) {
         if (Direction > 0){
             
             Debug.Log ("Hit Enemy w/light");
             target.GetComponent<Entity> ().TakeDamage (lightAtkDmg);
         }
     } 

     if (target.gameObject.tag == "Destructible" && lightDistance < 1) {
         if (Direction > 0){
             
             Debug.Log ("Hit Destructible w/light");
             target.GetComponent<Entity> ().TakeDamage (lightAtkDmg);
         }
     } 


     if (target.gameObject.tag == "Magic" && lightDistance < 15 && lightDistance > 1) {
         if (Direction > 0) {
             Debug.Log ("magic deflected w/light");
         }
     }

     isAttacking = false; 

 } 
 

}

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

0 Replies

· Add your reply
  • Sort: 

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

How to Implement a “Parry” mechanic to a 2D game? 1 Answer

How to do bullet spread in 2D? 1 Answer

2D 360 Shooting Is not working (Top Down, Shooting in all directions) 1 Answer

How do I move camera towards the mouse while anchoring it to the player? 0 Answers

How to create a cinemachine custom camera offset in the aiming direction 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