• 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 tiyyargee · May 14, 2016 at 09:59 AM · c#animatorscript.animationsanimator controller

how i can stop the animator to play trigger animation?

hey guys , i have an enemy script that detect the distance to the player and do actions....so when the enemy health is <= 0 i want him to die ..if(health<=0){ animator.SetTrigger("die")}, the problem i have is the enemy is keep playing die animation, i know the problem is the enemy is keep checking the distance to the player but i dont know how to solve this here is the script: using UnityEngine; using System.Collections;

public class enenyscript : MonoBehaviour { public Transform player; Animator anim; public float inrange; public CharacterController cc; public float speed; public int health; public float destroytime;

 // Use this for initialization
 void Start () {
     anim = GetComponent<Animator>();
   
     
 }
 
 // Update is called once per frame
 void Update ()
 {
     if(inRange())
     {
         transform.LookAt(player.position);
         anim.SetBool("attack",true);
         
        
         
     }
     else if(!inRange())
     {
         Chase();
         anim.SetBool("attack",false);
         
     }
     
 
 }

 bool inRange()
 {
     if (Vector3.Distance(transform.position, player.position) <=inrange)
     {
         return true;
     }
     else
     {
         return false;
     }

 }

 void Chase()
 {
     transform.LookAt(player.position);
     cc.SimpleMove(transform.forward * speed);
     anim.SetFloat("Speed",1);
    

 }

  
 public void gethit(int damage)
 {
     health = health - damage;
     if(health<0)
     {
         health = 0;
         anim.SetTrigger("die");

         
        




     }
 }


 

 void OnMouseOver()
 {
     playercombat.opponent = transform;
 }

 

}

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 cmonroy · May 14, 2016 at 06:02 PM

Check your update function...

if(enemy == alive) { // do your stuff.. } else { // do nothing, since the enemy is dead... }

Comment
Add comment · 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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

I'm still not get it how to mix/blend soldier character weapon aiming animation with walking animation ? 1 Answer

Opening one door in a scene causes all others to open 1 Answer

How do i use the animator avatar mask to combine two animations ? 0 Answers

Animator switching between floats 1 Answer

How to make an animator controller efficient 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges