hey guys i made a animation and it worked and all but when i pressed play to test it it kept saying the animation state could not be played because it could not be found… i dont get it what should i do? heres the coding i used.
#pragma strict
var TheDamage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
var TheMace : Transform;
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
TheMace.animation.Play("Mace attack");
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
I can’t see any obvious errors, so all I can do is show you tutorials that helped me and my Java-Script with animations in. A notation tells you where the animation is.
var speed : float = 6.0;
var twiceSpeed : float = 10.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
var rotateSpeed : float = 3.0;
private var moveDirection : Vector3 = Vector3.zero;
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
//Grounded, so recalculate
//Move directly from axes
moveDirection = Vector3(0, 0, Input.GetAxis("Vertical"));
//Rotation Code
transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
//Animation Code
if (Input.GetKeyDown("w"))
{
animation.Play("Full Walk");
}
else if (Input.GetKeyUp("w"))
{
animation.Stop();
animation.Play("Idle");
}
}
//Apply Gravity
moveDirection.y -= gravity * Time.deltaTime;
//Move Controller
controller.Move(moveDirection * Time.deltaTime);
}
Bones: Unity 3D Tutorial Part 14: Playing With Bones - YouTube
Animation: Unity 3D Tutorial Part 15: Basic Animation - YouTube
You need to make sure you have the Animation component attached to TheMace.
Also, you need to add the animations in your Project tab into the component. Make sure the animations are named correctly!