Animator Script Help!

Hello Everyone,
I am have a problem writing a simple piece of c# script that will allow me to activate an animation through the HoloLens via voice command. I have created the animation and controller.
With the controller I have inserted my animation and an empty default state. With the transition between the empty default state and my animation I have a Bool created. Upon running the scene the animator transitions from Entry to Default state and hangs there fine. As soon as I activate the bool the transition happens between the default state and animation.
Now all I need to do is create a code that will allow me to activate the bool via voice command from HoloToolKit speech manager.
Any help with this script would be much appreciated!

public static int AnimatorBool = Animator.StringToHash("NameOfBool");
...
var animator = GetComponent<Animator>()
animator.SetTrigger(AnimatorTrigger);
animator.SetBool(AnimatorTrigger, true);

Thank you rakkarage for your input! I created the following script and the error message that I am getting is Parameter ‘Hash - 707381567’ does not exist. UnityEngine.Animator:SetTrigger(Int32)
Maybe I have written something incorrectly? Thanks for your help!!

using System.Collections;
using System.Collections.Generic;
using HoloToolkit.Unity;
using HoloToolkit.Unity.InputModule;
using UnityEngine;
using UnityEngine.UI;

public class CameraOneVoiceBool : MonoBehaviour

{
    public Animator anim;
    public static int AnimatorTrigger = Animator.StringToHash("Trigger");
    public static int AnimatorBool = Animator.StringToHash("CameraOneBool");
   
    public void Start()
    {
        anim = GetComponent<Animator>();
    }

    private void Update()
    {
        var animator = GetComponent<Animator>();

        animator.SetTrigger(AnimatorTrigger);

        animator.SetBool(AnimatorTrigger, true);

    }

}

you are using the trigger in the bool, change

  • animator.SetBool(AnimatorTrigger, true);

to

  • animator.SetBool(AnimatorBool , true);

also for best results cache animator too

  • var animator = GetComponent();

maybe in Awake or Start so dont have to GetComponent each frame

edit oh you are :slight_smile: just not using it

Thank you! Your help is much appreciated. I do not have any code errors now the only problem is that the animation plays as soon as the gameobject is active. Here is the code.

using System.Collections;
using System.Collections.Generic;
using HoloToolkit.Unity;
using HoloToolkit.Unity.InputModule;
using UnityEngine;
using UnityEngine.UI;

public class CameraOneVoiceBool : MonoBehaviour

{
    public Animator animator;
    public static int AnimatorTrigger = Animator.StringToHash("CameraOneVoiceBool");
    public static int AnimatorBool = Animator.StringToHash("CameraOneVoiceBool");
   
    public void Start()
    {
        animator = GetComponent<Animator>();
    }

    private void Update()
    {

        animator.SetTrigger(AnimatorTrigger);

        animator.SetBool(AnimatorBool, true);

    }

}

animator.SetTrigger(AnimatorTrigger);

animator.SetBool(AnimatorBool, true);

don’t just call these every ftame… call one (which one starts your anim) when you want to set that bool or trigger

for example can put one in OnMouseDown or something

also make sure default in animator properties is unchecked