- Home /
Animation there but not playing?
I have this code here:
private var right_left_1=false;
private var back_front_1=false;
private var back_front_2=false;
private var screenCenter = new Vector3(0.5F, 0.5F, 0);
private var hit : RaycastHit;
function Update () {
var ray = Camera.main.ViewportPointToRay(screenCenter);
//right left 1
if(Input.GetButton("Fire1")&& right_left_1==false){
if (Physics.Raycast (ray, hit, 1000)) {
if(hit.transform.tag=="BlueRightLeft1"){
rl1();
}
}
}
//back front 1
if(Input.GetButton("Fire1")&& back_front_1==false){
if (Physics.Raycast (ray, hit, 1000)) {
if(hit.transform.tag=="BlueBackFront1"){
bf1();
}
}
}
//back front 2
if(Input.GetButton("Fire1")&& back_front_2==false){
if (Physics.Raycast (ray, hit, 1000)) {
if(hit.transform.tag=="BlueBackFront2"){
bf2();
}
}
}
}
function rl1(){
hit.transform.animation.Blend("BlueRightLeftOut1");
right_left_1=true;
yield WaitForSeconds(5);
hit.transform.animation.Blend("BlueRightLeftIn1");
yield WaitForSeconds(1);
right_left_1=false;
}
function bf1(){
hit.transform.animation.Blend("BlueBackFrontOut1");
back_front_1=true;
yield WaitForSeconds(5);
hit.transform.animation.Play("BlueBackFrontIn1");
yield WaitForSeconds(1);
back_front_1=false;
}
function bf2(){
hit.transform.animation.Blend("BlueBackFrontOut2");
back_front_2=true;
yield WaitForSeconds(5);
hit.transform.animation.Blend("BlueBackFrontIn2");
yield WaitForSeconds(1);
back_front_2=false;
}
The animations that seem to play are the last block moved. I tried moving them individually ant they work.
The error code:
The animation state BlueRightLeftIn1 could not be played because it couldn't be found! Please attach an animation clip with the name 'BlueRightLeftIn1' or call this function only for existing animations. UnityEngine.Animation:Blend(String) $:MoveNext() (at Assets/Scripts/MoveBlues.js:116)
The object the raycast is hitting has all animations attached to it? In animation settings on your object you can add animations and name them.
animations are added in animation panel...they also work, i've tested them individually. When i try to play them all toghether they wont work.... the "BlueXXXXXIn" animations, the others work
not really sure...i didn't put that in code but it should be start finish from 0 to 2 sec( animations are done with unity)
Solved(sort of) insted of putting 2 animations to play i used one big one with an animated pause.
function bf2(){ hit.transform.animation.Blend("BlueBackFrontOut2");//longer animation back_front_2=true; yield WaitForSeconds(8); back_front_2=false;
}
Answer by bompi88 · May 10, 2012 at 10:11 PM
Are you sure you have set up your gameObject/Prefab as on this image? Where you should have all of your animations, like for example: BlueRightLeftOut1, BlueRightLeftIn1 etc. ( This i not an answer, but I need to show an image.)
yes i did...as i said animation work but not all together
Your answer
Follow this Question
Related Questions
Animation Window Time Unit 2 Answers
How do I make the animation play once then change scene? 0 Answers
Gun script help 1 Answer
Loop animation with a wait in between 3 Answers
Can the animation editor create local rotational data? 3 Answers