- Home /
(C#) Problem with animations not playing
Hello, I am making my first attempt at getting animations to play through a script and I'm having a problem where it says: "The animation state Jump (or Run, or Attack) could not be played because it couldn't be found!". I have three animations named Run, Jump, and Attack, and I've set these up in the model settings in the inspector with the frame ranges and whatnot. When I first imported the animation onto the model and got it into unity and hadn't split up the animations or given them names or frame ranges, the animation cycle was playing when I played the project, but now that I've split the animations, I'm getting the error message listed above. Here's the code I'm using:
using UnityEngine;
using System.Collections;
public class movement : MonoBehaviour {
public float speed = 6.0F;
public float jumpHeight = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
CharacterController controller;
public bool isAttacking { get { return _isAttacking; } set { _isAttacking = value; } }
bool _isAttacking = false;
void Start(){
controller = GetComponent<CharacterController>();
}
void Update() {
if (controller.isGrounded) {
moveDirection = Vector3.forward;
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButtonDown("Jump"))
{
moveDirection.y = jumpHeight;
animation.Play("Jump");
}
}
if (Input.GetButtonDown("Fire1"))
{
Attack ();
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
public void Attack()
{
StartCoroutine(Attack_Coroutine());
}
private IEnumerator Attack_Coroutine()
{
_isAttacking = true;
animation.Play("Attack");
yield return new WaitForSeconds(1);
_isAttacking = false;
}
}
Is there something I need to be doing to get the script to recognize the animations?
Answer by TheDarkVoid · Dec 05, 2012 at 09:40 PM
is your script on the same gameObject with the animations, are the animations correctly assigned to the animations list in the animation component? see here
That seems to have been what the problem was. I didn't assign anything in the list, just on the model. Thanks so much!
Your answer
Follow this Question
Related Questions
Rotate similar child objects around own origin 2 Answers
Problem with messenger extended 0 Answers
Identifier help 1 Answer
Animated Texture Offset 1 Answer
Animation Error 0 Answers