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 /
  • Help Room /
avatar image
0
Question by gettinjacob · May 07, 2021 at 10:04 PM · bug-perhapsnotworking

Attack Overlapbox Not working

My Attack doesnt work like it should be, when i clicked the attack it damages the enemy even not being inside the collider. any help would be appreciated this bugged me for days

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Pointweapon : MonoBehaviour
 {
     [Header("Weapon Hand")]
     public GameObject _Weaponhand;
     public Animator anim;
 
     [Header("Dash")]
     public Rigidbody2D playerds;
     public float dashspeed = 500f;
 
     [Header("Attack")]
     public LayerMask _Whatenemy;
     public float _AttackrangeX;
     public float _AttackrangeY;
     public int _Damage = 10;
     public float _Gizmorange;
     [Header("Attack Timer")]
     public float _TimeBtwAttk;
     public float _StartTimeBtwAttk;
 
     private void Update()
     {
         if (_TimeBtwAttk <= 0)
         {
             Attack();
             _TimeBtwAttk = _StartTimeBtwAttk;
         }
         else
         {
             _TimeBtwAttk -= Time.deltaTime;
         }
     }
 
     private void FixedUpdate()
     {
         Pointer();
     }
 
     private void Pointer()
     {
         Vector3 _Difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
         _Difference.Normalize();
         float _rotationz = Mathf.Atan2(-_Difference.x, _Difference.y) * Mathf.Rad2Deg;
         transform.rotation = Quaternion.Euler(0f, 0f, _rotationz);
     }
 
     private void Attack()
     {
         if (Input.GetKey(KeyCode.X))
         {
             Collider2D[] _enemiestohurt = Physics2D.OverlapBoxAll(new Vector3(0,_Gizmorange,0), new Vector2(_AttackrangeX,_AttackrangeY), 0, _Whatenemy);
             for (int i = 0; i < _enemiestohurt.Length; i++)
             {
                 _enemiestohurt[i].GetComponent<Enemy>().Takedamage(_Damage);
             }
         }
         anim.SetTrigger("idle");    
     }
 
     private void dash()
     {
         Vector3 Dashpos = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
         playerds.AddForce(Dashpos * dashspeed);
         anim.SetTrigger("swing");
     }
 
     private void OnDrawGizmosSelected()
     {
         Gizmos.color = Color.yellow;
         Gizmos.matrix = this.transform.localToWorldMatrix;
         Gizmos.DrawWireCube(new Vector3(0,_Gizmorange,0), new Vector3(_AttackrangeX,_AttackrangeY, 1));
         //Gizmos.DrawWireCube(_Attackpos.position, new Vector3(_AttackrangeX,_AttackrangeY, 1));
     }
 }
 

help.png (163.3 kB)
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

159 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

Related Questions

Switching shader back and forth fixes transparency issue? 0 Answers

Terrain Disappear 0 Answers

Trouble with rotating player when gravity is shifted 0 Answers

Issue when terrain or ground is not plane, a bug or programming? 0 Answers

How to close debuggers/decompilers/reflectors, including IDEs? 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