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 /
avatar image
0
Question by ievets · Sep 22, 2011 at 03:45 AM · damage

Colliding damage on Enemy even when not attacking?

Hi everyone. I have a problem with my colliders. Right now I have a combo attack. I also have a sword that is attached to the hand. I'm able to do my combo moves and I've set a collision on my sword so that it can do damage when it comes into contact with the enemy. The only problem is...the collision happens even when I'm not doing my combo moves. If I stand close enough and let the sword just touch the enemy, it will do damage. Is there a code or script I have to add in to tell the collider to only work when i'm attacking?

Thanks. I'm doing this as a learning process and any help or tips would be appreciated.

Script for my Sword:


var damage : int = 10;

function OnTriggerEnter (other : Collider) {

   var Enemy : Enemy = other.GetComponent("Enemy");

 if (Enemy != null)

     Enemy.ApplyDamage(damage);

}


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 syclamoth · Sep 22, 2011 at 03:48 AM

Well, you can have a boolean value on your sword, which you set to true if you are attacking. Then, in your OnTrigger, do something like this-

 if(attacking)
 {
     // do damage things
 }
Comment
Add comment · Show 2 · 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 ievets · Sep 22, 2011 at 04:24 AM 0
Share

Sorry I'm still confused. I'm very new to the scripting world. I looked up some stuff on boolean. But I'm not sure what to do. Does the boolean make it so the sword's collision is off when I'm not attacking? I basically want to have character only do damage when the sword collides with the enemey but only when I push my attack command. DId you mean I have to add the boolean to the my Sword script? Sorry for the many questions

avatar image syclamoth · Sep 22, 2011 at 05:37 AM 0
Share

Yes, in your sword script set the boolean to true when the attack begins, and the set it to false when the attack ends.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Urgent help for Unity Game with deadline tomorrow 0 Answers

Damage Meter 1 Answer

How to have deformation/denting of 2D objects on impact? 1 Answer

cant seem to get damage on collision to work 0 Answers

Damage not reducing to enemy every second 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