- Home /
Problem Animation Blend
Hi i have problem blend, I add animation.Blend but doesn't work... Can you check my code and answers?
My code's:
function OnGUI () {
if(GUI.Button (Rect (215,Screen.height - 30,60,20), "Enter")){
animation["Red"].wrapMode = WrapMode.Once;
animation.Blend("Red");
}
else
{
if(GUI.Button (Rect (290,Screen.height - 30,60,20), "Enter")){
animation["Green"].wrapMode = WrapMode.Once;
animation.Blend("Green");
}
}
}
Sorry my bad speak english.
Answer by whydoidoit · Mar 26, 2013 at 06:17 PM
If your animation is on the same layer or higher than any other animations then that code will work presuming the animation is actually enabled and playing.
perhaps
var red = animation["Red"];
red.wrapMode=WrapMode.Once;
red.speed = 1;
red.enabled = true;
animation.Blend("Red");
Thanks for speed reply. But doesn't work your code with animation blend.
Ah ok, maybe red.time = 0; as well (put it back to the beginning)
Also your OnGUI is a bit weird - with that embedded second button overlaying the first. I don't think you mean to do that - remember the first if(GUI.Button) will be false nearly all the time. When you press it then for a single frame it will be true. So I don't think you can ever press the "Red" button...It's always hidden by the other one. I spaced them out
function OnGUI () {
var red = animation["Red"];
var green = animation["Green"];
if (GUI.Button (Rect (215,Screen.height - 30,60,20), "Enter")){
red.wrap$$anonymous$$ode=Wrap$$anonymous$$ode.ClampForever;
red.speed = 1;
red.enabled = true;
red.layer = 3000;
red.time = 0;
animation.Blend("Red");
}
if (GUI.Button (Rect (315,Screen.height - 30,60,20), "Enter")){
green.wrap$$anonymous$$ode=Wrap$$anonymous$$ode.ClampForever;
green.speed = 1;
green.enabled = true;
green.layer = 3000;
green.time = 0;
animation.Blend("Green");
}
}
Your answer
