- Home /
Question by
JackoMiG · Jul 06, 2015 at 11:55 AM ·
javascriptanimatormecanimanimator controller
How to script SetTrigger (JS)?
Hi,
I would like to activate a Trigger in Mecanim by pressing mouse 0. How do I script this in Javascript?
I imagine it would involve:
if(Input.GetButton("Fire1"))
{
animator.SetTrigger(I don't know what to put here)
}
This is what I got so far:
#pragma strict
var animator : Animator; //stores the animator component
var v : float; //vertical movements
var h : float; //horizontal movements
var sprint : float;
var r : boolean = false;
function Start () {
animator = GetComponent(Animator); //assigns Animator component when we start the game
}
function Update () {
v = Input.GetAxis("Vertical");
h = Input.GetAxis("Horizontal");
Sprinting();
Firing();
Reloading();
}
function FixedUpdate () {
//set the "Walk" parameter to the v axis value
animator.SetFloat ("Walk", v);
animator.SetFloat ("Turn", h);
animator.SetFloat("Sprint", sprint);
animator.SetTrigger("Fire"
}
Do I need to include variables for this? If so then what? Thanks.
Comment
Hello,
You have to implement your trigger via the animator tools (outside playmode) you can then activate it with animator.SetTrigger() passing the name of the trigger to this function.
I don't know what you are trying to do (explain?) but maybe your state-machine could just be improved.
Best Answer
Answer by JackoMiG · Jul 10, 2015 at 04:16 AM
To answer my question (in case others search this) to set a trigger parameter you need to go something like:
var animator : Animator; //stores the animator component (variable for the animator)
if(*condition*)
{
animator.SetTrigger("NAMEOFPARAMETER")
}