Answers for "unity animator set bool"

C#
2

unity animator set bool

// unity animator set bool
// Fetch the Animator
Animator m_Animator;
// Use this for deciding if the GameObject can jump or not
bool m_Jump;

void Start()
{
    //This gets the Animator, which should be attached to the GameObject you are intending to animate.
    m_Animator = gameObject.GetComponent<Animator>();
    // The GameObject cannot jump
    m_Jump = false;
}

void Update()
{
    //Click the mouse or tap the screen to change the animation
    if (Input.GetMouseButtonDown(0))
        m_Jump = true;

    //Otherwise the GameObject cannot jump.
    else m_Jump = false;

    //If the GameObject is not jumping, send that the Boolean “Jump” is false to the Animator. The jump animation does not play.
    if (m_Jump == false)
        m_Animator.SetBool("Jump", false);

    //The GameObject is jumping, so send the Boolean as enabled to the Animator. The jump animation plays.
    if (m_Jump == true)
        m_Animator.SetBool("Jump", true);
}
Posted by: Guest on July-12-2021
1

unity animator get bool

// unity animator get bool
//Fetch the Animator
Animator m_Animator;
// Use this to decide if the GameObject can jump or not
bool m_Jump;

void Start()
{
    //This gets the Animator, which should be attached to the GameObject you are intending to animate.
    m_Animator = gameObject.GetComponent<Animator>();
    // The GameObject cannot jump
    m_Jump = false;
}

void Update()
{
    //Press the space bar to enable the "Jump" parameter in the Animator Controller
    if (Input.GetKey(KeyCode.Space))
    {
        //Set the "Jump" parameter in the Animator Controller to true
        m_Animator.SetBool("Jump", true);
        //Check to see if the "Crouch" parameter is enabled
        if (m_Animator.GetBool("Crouch"))
        {
            //If the "Crouch" parameter is enabled, disable it as the Animation should no longer be crouching
            m_Animator.SetBool("Crouch", false);
        }
    }
    //Otherwise the "Jump" parameter should be false
    else m_Animator.SetBool("Jump", false);

    //Press the down arrow key to enable the "Crouch" parameter
    if (Input.GetKey(KeyCode.DownArrow))
        m_Animator.SetBool("Crouch", true);
    else
        m_Animator.SetBool("Crouch", false);
}
Posted by: Guest on July-12-2021

Code answers related to "unity animator set bool"

C# Answers by Framework

Browse Popular Code Answers by Language