- Home /
How do I play trigger parameters properly in the animator controller /
I have two different enemy ai I only gotten one trigger parameter to play on one of my enemy ai . I name the trigger parameter the same as the other enemy ai . I change one of the enemy ai and the die animation still didn't work when I kill the enemy ai . The die animation is not set on loop . I also tried closing the animator tab and restarting . I deleted the parameter and re-adding the parameter press and die animation still don't work. Here is my script :
// Exposed properties
public bool Invincible { set { m_Invincible = value; } }
public float MaxHealth { set { m_MaxHealth = value; } }
public float MaxShield { set { m_MaxShield = value; } }
public float CurrentHealth { get { return m_CurrentHealth; } }
public float CurrentShield { get { return m_CurrentShield; } }
public float ShieldRegenerativeAmount { set { m_ShieldRegenerativeAmount = value; } }
public AudioClip deathClip;
public bool isSinking;
static Animator anim;
void Start ()
{
anim = GetComponent<Animator> ();
}
// Internal variables
#if ENABLE_MULTIPLAYER
[SyncVar(hook = "SetHealthAmount")]
#endif
private float m_CurrentHealth;
#if ENABLE_MULTIPLAYER
[SyncVar(hook = "SetShieldAmount")]
#endif
private float m_CurrentShield;
private ScheduledEvent m_ShieldRegenerativeEvent;
private float m_SpawnTime;
// SharedFields
protected float SharedProperty_MaxHealth { get { return m_MaxHealth; } }
protected float SharedProperty_MaxShield { get { return m_MaxShield; } }
protected float SharedProperty_CurrentHealth { get { return m_CurrentHealth; } }
protected float SharedProperty_CurrentShield { get { return m_CurrentShield; } }
// Component references
protected GameObject m_GameObject;
protected Transform m_Transform;
private Rigidbody m_Rigidbody;
/// <summary>
/// Cache the component references and initialize the default values.
/// </summary>
protected virtual void Awake()
{
anim = GetComponent <Animator>();
m_GameObject = gameObject;
m_Transform = transform;
m_Rigidbody = GetComponent<Rigidbody>();
SharedManager.Register(this);
m_CurrentHealth = m_MaxHealth;
m_CurrentShield = m_MaxShield;
// Register for OnRespawn so the health and sheild can be reset.
EventHandler.RegisterEvent(m_GameObject, "OnRespawn", OnRespawn);
}
if (m_DeactivateOnDeath) {
Scheduler.Schedule(m_DeactivateOnDeathDelay, Deactivate);
GetComponent<AudioSource>().Play();
anim.SetTrigger("Dead");
anim.SetTrigger("death");
}
}
Answer by rmassanet · Jul 22, 2016 at 07:22 AM
If you look at the bottom of the screenshot, you will see the message console is telling you that there is no death
parameter declared in the Animator.
However, in your screenshot, I see a death
trigger parameter declared. Could it be that you are editing an animation controller, different than the one that is attached to the script's game object?
The die animation time is different from the other gameobject.
An Animator is not the same thing as an Animation. The script you posted, is attached to a GameObject. That GameObject should have an Animator attached, because you are requesting it. Does that Animator have a death
trigger parameter?