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 bandit322 · Dec 14, 2018 at 02:05 PM · 2d-platformerattackboxcollider2dtimed

Help: My timed enemy attack is not attacking at all.

Hey there! Well I've been working on this mechanic for a while now (an embarrassing amount of weeks) and was unable to get it working properly so I decided to see if anyone else experienced this, but I couldn't find any other issues like this, so I came here for help.

So basically, I want my enemy to follow the player, stop once in attack range, wind up an attack (part of the attack animation), then once the animation visibly smashes I want the box collider to activate and trigger if the player is there. The time interval between attacks would be 2 seconds, but if the player escapes the attack I want the enemy to become stuck for double the interval, 4 seconds, until it's free to either move or attack again.

This is the script thats giving me the issues, it's connected to a box collider around the area of the enemy that detects the player, note: this does not damage the player it only detects it to then enable the actual collider that damages the player. These are the variables I'm using:

     public GrimaceBehaviour Grim;           //Main controller
     public Collider2D GrimSmash;            //The attack's collider
     public FollowDetect follow;             //The follow collider/script
 
     public float attkTimer = 2f;           //Attack interval
 
     public float attkCD;                    //Variable to set to interval
     public int attkDmg = 2;                 //The attack's damage
 
     [HideInInspector]
     public bool attacking;                  //Attack anim
     [HideInInspector]
     public bool stuck;                      //Stuck in ground anim
     [HideInInspector]
     public bool inRange = false;
     public bool canAttk = false;

These are the methods:

 public void Start()
     {
         attkCD = attkTimer;
         Grim = gameObject.GetComponentInParent<GrimaceBehaviour>();   
         GrimSmash.enabled = false;
         follow.enabled = true;
         
     }
 
     void Update()
     {
 
 
             if (attacking == true && canAttk)
             {             
                 follow.enabled = false;     //stops enemy from moving
             }
             else
             {
                 follow.enabled = true;      //starts movement
                  
             }
         
       }
 
 
 
 
     public void OnTriggerStay2D(Collider2D col)
     {
         
      
 
            if (attkCD > 0)
             {
                 if (col.CompareTag("Player"))
                 {
                     inRange = true;
                     follow.enabled = false;
                     attacking = false;
                     attkCD -= Time.deltaTime;   //countdown to attack
 
                 }
 
             }
             else
             {
                 canAttk = true;
                 Grim.anim.SetBool("Attack", true);
                 Pause();
                 GrimSmash.enabled = true;
                 attkCD = attkTimer;                 //resets countdown       
 
 
             }
 
     }
 
     public void OnTriggerExit2D(Collider2D col)
     {
         if (col.CompareTag("Player"))
         {
             inRange = false;
             follow.enabled = true;
         }
     }
 
     IEnumerator Pause()
     {
         yield return new WaitForSecondsRealtime(2f);
     }
 }

Any insights you can give are greatly appreciated. I know my code can be hard to follow, so if any further clarification is needed I will gladly give it. Thank you very much if you try and assist me, I can admit I dearly need it.

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

165 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

Related Questions

Help 2D attack 1 Answer

Changing gravity scale through collisions 0 Answers

Timer-Based Attack System 0 Answers

Player get's stuck on Tilemap Collider 2D 0 Answers

Charecter keeps playing walking animation after punching 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