Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.
Options

Start and Reset animator in Unity using voice control

Hi guys,

I’m burnt out with this so I’m hoping someone can help.

I have an animation created in the Animator component called ‘LNG Ship’. I want the animation to start when I use the word ‘Start’ and I want the animation to reset it’s original position when I use the word ‘Reset’. Its a basic animation - The ship starts in position A and moves to position B over 20 secs or so.

I have tried all sorts to get it working and I’m at the point of being lost in a load of code that makes no sense any more. I understand I need to be using the Speech input Source for defining the keyword and the Speech Input Handler to carry out the tasks based on my keyword.

Can anyone help me with the script please. I’m learning C# as I go along and what I thought was going to be an fairly straight forward bit of code is ruining me. I’m sure it’s straight fwd when you know how, but I just don’t know enough yet to get it to work. I’ve watched various tutorials and read numerous forum posts but I’ve not come up with anything that works at all.

For info I have the animation in an default statein the animator, so it does nothing right now. I was hoping to then get it to initilise though a script by using a key word.

Hopefully this makes sense.

Thanks in advance.

Best Answer

  • Options
    Gary_BGary_B
    edited March 2018 Answer ✓

    Hi,

    I managed to solve it. The problem was I was mixing old ISpeechHandler code with the new Speech Input Source/Handler components.

    It's stupidly simple...I think I had just reached that point in the day and rage quit.

    Thanks for the reply

    This is the script I used in the end and just referenced the Animate() and ResetAnimation() components in the Speech Input Handler.

    using HoloToolkit.Unity.InputModule;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class AnimationController : MonoBehaviour
    {
    
    public Animator anim;
    
    public void Start()
    {
    
        anim = GetComponent<Animator>();
        gameObject.SetActive(false);
    
    }
    
    public void Animate()
    {
    
        gameObject.SetActive(true);
        anim.Play("LNG Ship");
    
    
    }
    
    
    public void ResetAnimation()
    {
    
        gameObject.SetActive(false);
        anim.Play("Static");
    
    }
    
    
    }
    

Answers

  • Options
    dbarrettdbarrett ✭✭✭

    How do you have your animations set up? Do you change animations based on a parameter change? If you have your animations set up properly then it is only a matter of setting up your Speech Input Source and Speech Input Handler. If you do not have this part set up then I would suggest looking at Unity's tutorials for setting up animations and animators.

    You add your keyword to the Speech Input Source. Now you can add a keyword onto your Speech Input Handler. Here is where you add the functionality to your keyword. It works the same way as any Button event does in Unity. Drag and drop your object containing your "ChangeAnimation" script and select the method to perform.

    If you want this keyword to be able to be spoken anywhere inside the app then check the isGlobalListener box.

    AR Developer

  • Options
    Gary_BGary_B
    edited March 2018 Answer ✓

    Hi,

    I managed to solve it. The problem was I was mixing old ISpeechHandler code with the new Speech Input Source/Handler components.

    It's stupidly simple...I think I had just reached that point in the day and rage quit.

    Thanks for the reply

    This is the script I used in the end and just referenced the Animate() and ResetAnimation() components in the Speech Input Handler.

    using HoloToolkit.Unity.InputModule;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class AnimationController : MonoBehaviour
    {
    
    public Animator anim;
    
    public void Start()
    {
    
        anim = GetComponent<Animator>();
        gameObject.SetActive(false);
    
    }
    
    public void Animate()
    {
    
        gameObject.SetActive(true);
        anim.Play("LNG Ship");
    
    
    }
    
    
    public void ResetAnimation()
    {
    
        gameObject.SetActive(false);
        anim.Play("Static");
    
    }
    
    
    }
    
  • Options

    Hi,
    I managed to solve it. The problem was I was mixing old ISpeechHandler code with the new Speech Input Source/Handler components.
    It's stupidly simple...I think I had just reached that point in the day and rage quit.
    Thanks for the reply
    This is the script I used in the end and just referenced the Animate() and ResetAnimation() components in the Speech Input Handler.

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

    public class AnimationController : MonoBehaviour
    {

    public Animator anim;
    
    public void Start()
    {
    
        anim = GetComponent<Animator>();
        gameObject.SetActive(false);
    
    }
    
    public void Animate()
    {
    
        gameObject.SetActive(true);
        anim.Play("LNG Ship");
    
    
    }
    
    
    public void ResetAnimation()
    {
    
        gameObject.SetActive(false);
        anim.Play("Static");
    
    }
    

    }

  • Options

    Hi,
    I managed to solve it. The problem was I was mixing old ISpeechHandler code with the new Speech Input Source/Handler components.
    It's stupidly simple...I think I had just reached that point in the day and rage quit.
    Thanks for the reply
    This is the script I used in the end and just referenced the Animate() and ResetAnimation() components in the Speech Input Handler.

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

    public class AnimationController : MonoBehaviour
    {

    public Animator anim;
    
    public void Start()
    {
    
        anim = GetComponent<Animator>();
        gameObject.SetActive(false);
    
    }
    
    public void Animate()
    {
    
        gameObject.SetActive(true);
        anim.Play("LNG Ship");
    
    
    }
    
    
    public void ResetAnimation()
    {
    
        gameObject.SetActive(false);
        anim.Play("Static");
    
    }
    

    }

Sign In or Register to comment.