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 /
This question was closed Nov 19, 2016 at 08:51 AM by cyth1 for the following reason:

Other

avatar image
0
Question by cyth1 · Nov 18, 2016 at 10:21 PM · triggerontriggerenteranimationsmelee attack

OnTriggerEnter triggers many times per trigger.

I'm working on combat right now, and the way it's set up is that when a weapons trigger enters the enemy collider, and the weapons tag equals a specific weapon, and that attacks animation is playing, it does damage to the enemy. For instance, if the obj tag that enters the collider is "Fist", and the current animation playing is "RJab", then it deals 5hp to the enemy. When I hit the enemy however, like once, the console prints "RJab" like up to 29 times in that one jab. Here's my code for all that jazz:

 using UnityEngine;
 using System.Collections;
 
 public class ImpactReciever : MonoBehaviour
 {
 
     [SerializeField]
     protected Animator playerAnimator;
     [SerializeField]
     protected GameObject playerOBJ;
     public Enemy enemy;
 
 
 
     void Start()
     {
         playerOBJ = GameObject.FindGameObjectWithTag("Player");
         playerAnimator = playerOBJ.GetComponent<Animator>();
     }
 
     void Update()
     {
     }
 
     void OnTriggerEnter(Collider weapon)
     {
         bool attackHappening = false;
         if (weapon.tag == "Fist")
         {
             if (playerAnimator.GetCurrentAnimatorStateInfo(0).IsName("RJab"))
             {
                 Debug.Log("RJab Hit");
                 if (attackHappening)
                     enemy.TakeDamage(5f);
             }
 
         }
 
         else if (weapon.tag == "Fist2")
         {
             if (playerAnimator.GetCurrentAnimatorStateInfo(0).IsName("Jab"))
             {
                 attackHappening = true;
                 Debug.Log("Jab Hit");
                     enemy.TakeDamage(5f);
             }
         }
         if (weapon.tag == "Fist3")
         {
             if (playerAnimator.GetCurrentAnimatorStateInfo(0).IsName("Spinkick"))
             {
                 Debug.Log("Spinkick Hit");
                 enemy.TakeDamage(10f);
             }
         }
         if (weapon.tag == "Fist4")
         {
             if (playerAnimator.GetCurrentAnimatorStateInfo(0).IsName("armada"))
             {
                 Debug.Log("armada Hit");
                 enemy.TakeDamage(10f);
                 gameObject.GetComponent<Rigidbody>().AddForce(Vector3.back * 4);
             }
         }
     }
 }
 
 

Also I don't know if this may help, but I feel like it's triggering once per frame in my animations. If that's the case then my jab animation is 29 frames long. Just in case. I don't know. I've been trying for a long while to figure this out. How can I fix this?

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

  • Sort: 

Follow this Question

Answers Answers and Comments

90 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

Related Questions

Help with non stop looping animation!! 1 Answer

Trigger not detected 0 Answers

OnTriggerEvent doesn't work 1 Answer

Wrong Trigger causes action to run,Multiple Triggers cause the same event 0 Answers

My Trigger detection doesn't work when i reactivate the object it's on,Detect OnTriggerEnter2D after deactivating and reactivating the object 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