Okay, so i got this code
(C#)
using UnityEngine;
using System.Collections;
public class Stats : MonoBehaviour
{
public float Health;
public bool Dead;
private bool Invencible;
private float Counter;
private Animator Animator;
public float DeathCounter;
private bool AnimPlayed;
private bool MovementDisabled;
void Start ()
{
Animator = gameObject.GetComponent<Animator>();
DeathCounter = 6;
}
void Update()
{
if (Health > 100) { Health = 100; }
if (Health < 0) { Health = 0; }
if (Health == 0)
{
Die();
}
if (Invencible)
{
if (Counter <= 0)
{
Invencible = false;
}
else
{
Counter -= Time.deltaTime;
}
}
}
public void DealDamage (float Damage)
{
if(!Invencible)
{
Health -= Damage;
Invencible = true;
Counter = 1;
}
}
private void Die ()
{
if (!MovementDisabled)
{
Dead = true;
MovementDisabled = true;
}
if (DeathCounter <= 0)
{
Respawn();
}
else
{
if (DeathCounter <= 5)
{
DeathCounter = DeathCounter - Time.deltaTime;
if (!AnimPlayed)
{
AnimPlayed = true;
PlayAnim("Dead");
}
}
else
{
DeathCounter = DeathCounter - Time.deltaTime;
PlayAnim("Idle");
}
}
}
public void PlayAnim(string Name)
{
Animator.Play(Name, 0);
}
public void Respawn ()
{
}
}
And this animator (Please, tell me the animator navigation controlls)
But, anywhere in the code, when i try to play the animation “Dead” using
Animator.Play("Dead", 0);
it runs, and 2 seconds later (The code line is not even being executed)
Animator.GotoState: State could not be found
UnityEngine.Animator:Play(String, Int32)
Stats:PlayAnim(String) (at Assets/Systems/Character/Stat/Stats.cs:79)
Stats:Die() (at Assets/Systems/Character/Stat/Stats.cs:67)
Stats:Update() (at Assets/Systems/Character/Stat/Stats.cs:25)
The thing is, the animation plays fine. But the error makes me mad.
With other animations it works perfect, and, i even tried playing the animation from
other script, and, it don’t shows any error.
Is this a bug, or am i doing something wrong?
Unity hates me.
Thank you, and sorry for my english.