//Widget_Animation: Animation State Manager for Widget.
//controls layers, blends, and play cues for all imported animations
private var nextPlayIdle = 0.0;
var waitTime = 8.0;
var playerController: Widget_Controller;
playerController = GetComponent(Widget_Controller) ;
//Initialize and set up all imported animations with proper layers--------
function Start(){
//set up layers - high numbers receive priority when blending
((GetComponent.<Animation>() as Animation)["Widget_Idle"] as AnimationClip).layer = -1;
((GetComponent.<Animation>() as Animation)["Idle"] as AnimationClip).layer = 0;
//we want to make sure that the rolls are synced together
((GetComponent.<Animation>() as Animation)["SlowRoll"] as AnimationClip).layer = 1;
((GetComponent.<Animation>() as Animation)["FastRoll"] as AnimationClip).layer = 1;
((GetComponent.<Animation>() as Animation)["Duck"] as AnimationClip).layer = 1;
((GetComponent.<Animation>() as Animation)as AnimationClip).SyncLayer(1);
((GetComponent.<Animation>() as Animation)["Taser"] as AnimationClip).layer = 3;
((GetComponent.<Animation>() as Animation)["Jump"] as AnimationClip).layer = 5;
//these should take priority over all others
((GetComponent.<Animation>() as Animation)["FallDown"] as AnimationClip).layer = 7;
((GetComponent.<Animation>() as Animation)["GotHit"] as AnimationClip).layer = 8;
((GetComponent.<Animation>() as Animation)["Die"] as AnimationClip).layer = 10;
((GetComponent.<Animation>() as Animation)["Widget_Idle"] as AnimationClip).wrapMode = WrapMode.PingPong;
((GetComponent.<Animation>() as Animation)["Duck"] as AnimationClip).wrapMode = WrapMode.Loop;
((GetComponent.<Animation>() as Animation)["Jump"] as AnimationClip).wrapMode = WrapMode.ClampForever;
((GetComponent.<Animation>() as Animation)["FallDown"] as AnimationClip).wrapMode = WrapMode.ClampForever;
//Make sure nothing is playing by accident, then start with a default idle.
GetComponent.<Animation>().Stop();
GetComponent.<Animation>().Play("Idle");
}
//Check for which animation to play------------------------------------
function Update(){
//on the ground animations
if(playerController.IsGrounded()){
GetComponent.<Animation>().Blend("FallDown", 0, 0.2);
GetComponent.<Animation>().Blend("Jump", 0, 0.2);
//if boosting
if (playerController.IsBoosting())
{
GetComponent.<Animation>().CrossFade("FastRoll", 0.5);
nextPlayIdle = Time.time + waitTime;
}
else if(playerController.IsDucking()){
GetComponent.<Animation>().CrossFade("Duck", 0.2);
nextPlayIdle = Time.time + waitTime;
}
// Fade in normal roll
else if (playerController.IsMoving())
{
GetComponent.<Animation>().CrossFade("SlowRoll", 0.5);
nextPlayIdle = Time.time + waitTime;
}
// Fade out walk and run
else
{
GetComponent.<Animation>().Blend("FastRoll", 0.0, 0.3);
GetComponent.<Animation>().Blend("SlowRoll", 0.0, 0.3);
GetComponent.<Animation>().Blend("Duck", 0.0, 0.3);
if(Time.time > nextPlayIdle){
nextPlayIdle= Time.time + waitTime;
PlayIdle();
}
else
GetComponent.<Animation>().CrossFade("Widget_Idle", 0.2);
}
}
//in air animations
else{
if(Input.GetButtonDown("Jump")){
GetComponent.<Animation>().CrossFade("Jump");
}
if(!playerController.IsGrounded()){
GetComponent.<Animation>().CrossFade("FallDown", 0.5);
}
}
//test for idle
if(Input.anyKey){
nextPlayIdle = Time.time + waitTime;
}
}
//Other functions--------------------------------------------
function PlayTaser(){
GetComponent.<Animation>().CrossFade("Taser", 0.2);
}
function PlayIdle(){
GetComponent.<Animation>().CrossFade("Idle", 0.2);
}
function GetHit(){
GetComponent.<Animation>().CrossFade("GotHit", 0.2);
}
function PlayDie(){
GetComponent.<Animation>().CrossFade("Die", 0.2);
}
@script AddComponentMenu("Player/Widget'AnimationManager")
This is my code, you don't need to look thorugh the whole thing if you don't want to. The key line where the error occurs is this one, also known from the error message as line 14.
((GetComponent.() as Animation)["Widget_Idle"] as AnimationClip).layer = -1;
So can anybody help please because I am stuck on this for a week now doing nothing but searching the internet and mostly this site in particular and found nothing. The script above is part of a Unity3D project and I am kinda new to it, so please explain in detail what the problem is and how can I fix it. I have read many posts in this site and most of the problems were resolved, hopefuuly the same happens here. Love you guys! You are the best! I can always count on help via this site and very friendly comunity.