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)