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 Robby-rEINEWALD · Oct 29, 2014 at 04:18 AM · animationcolliderdamage

Damage Animation doesn't play

I want to play animation damage when taking shot, but it doesn't play, just stop for a moment. This is my code

 function OnTriggerEnter(other : Collider){
     if(other.tag == "shot"){
         move = false;
         animation.Play("damage01");
         health--;
         Destroy(other);
     }
 }

 function Update(){
     if(move && health > 0){
         GetComponent(NavMeshAgent).destination = target.position;
         animation.Play("walk01");
     }
     playerDistance = Vector3.Distance(player.transform.position, transform.position);
     if(playerDistance <= 1){
         if(!attacking && health > 0){
             move = false;
             this.GetComponent(NavMeshAgent).Stop();
             animation.Play("attack01");
             Invoke("ApplyDamage", 1);
             attacking = true;
         }
     }
     if(playerDistance > 1 && !attacking && health > 0){
         move = true;
         animation.Play("walk01");
     }
     if(health <= 0){
         die();
     }
 }

Comment
Add comment · Show 2
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 AlwaysSunny · Oct 29, 2014 at 04:17 AM 0
Share

When asking questions, please detail what is happening versus what you intend to have happen.

avatar image iwaldrop · Oct 29, 2014 at 08:00 AM 0
Share

To be fair, both are equally important in reshaping existing behavior into desired behavior.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Gardosen · Oct 30, 2014 at 09:25 AM

On your OnTriggerEnter Method you are writing

  animation.Play("damage01");
  health--;
  Destroy(other);

is the animation played on the other object? if so, you have to wait till the animation is over, and then destroy it. otherwise he will start the animation but goes further in progress.

i also would recommend you to place the Destroy(other); call into a separate method like

 public void DestroyObject(GameObject _gameObject){
  Destroy(_gameObject);
 }

and then make a EvenTrigger call in your animation to this method.

this way you can synchronize the destroying of the object with a certain timeframe of your animation.

Greetings Gardosen

Comment
Add comment · Show 1 · 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 Robby-rEINEWALD · Oct 30, 2014 at 02:09 PM 0
Share

It doesn't work even I delete Destroy(other).

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Boolean doesn't change as I want 3 Answers

Make mesh collider constantly change 1 Answer

overlap half sphere? 0 Answers

Changing collider in a sprite manager 2 animation 0 Answers

How do I make the enemy ai animations play after the player exit the on trigger collider on the enemy ai 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