- Home /
Mecanim Boolean
Hello, I've made an animation script for my character using the mecanim parameter, float. Now i need to use a Boolean and i don't think I'm using it correctly, I'm not getting any errors but It's just not working.
#pragma strict
var animator : Animator; //stores the animator component
var v : float; //vertical movements
var h : float; //horizontal movements
var Sprint : float;
var Shoot : boolean;
function Start ()
{
animator = GetComponent(Animator); //asigns animator component when game is tarted
}
function Update ()
{
v = Input.GetAxis("Vertical");
h = Input.GetAxis("Horizontal");
Sprinting();
}
function FixedUpdate ()
{
//set the "Walk" parameter to the v axis value
animator.SetFloat ("Walk", v);
animator.SetFloat("Sprint", Sprint);
animator.SetBool("Shooting", true);
}
function Sprinting ()
{
if(Input.GetButton("Sprint"))
{
Sprint = 0.2;
}
else
{
Sprint = 0.0;
}
}
function Shooting ()
{
if(Input.GetButton("f"))
{
Shooting == true;
}
else
{
Shooting == false;
}
}
it is well known that $$anonymous$$echanim is a rascal when it comes to changing variable types/names. Try deleting that variable and creating a new with a different name. then reapply it to all the animations. :| it sucks I know
Answer by Baste · Dec 12, 2014 at 09:37 AM
If the boolean variable Shooting didn't exist, you would be getting a warning message to the console when you set it to true. Something along the lines of "The boolean parameter Shooting does not exist"
If you're not getting any of those, there's something wrong in your transitions. It's easy to check - when playing, select the model that's being animated, open the animator window, and see what's happening. You'll see the variables changing in real time.
Now, what's happening is that if you just click 'f', then the shooting parameter will be true for just a couple of frames - maybe too few frames for you to actually notice the correct animation playing. I'd guess it's either that, or that you haven't set up the animator correctly.