Question by
Roguespine · May 07, 2019 at 03:16 PM ·
getcomponent
Changing animation using GetComponent
Hello, i was trying to switch the animation of my object from running to jumping using a bool isJumping in the animator controller. The code i use in the script attached to the object that has the animator is
GetComponent<Animator>().SetBool("isJumping", true);
It works just fine, however before this I tried using the method in this video https://www.youtube.com/watch?v=HVCsg_62xYw (you can skip to 3:46 to see the code I'm having issues with) I wrote the code exactly as in the video so instead of using the aforementioned one I used
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerColl : MonoBehaviour
{
private Animator anim;
void Start(){
anim = GetComponent<Animator>();
}
void Update(){
if (condition)
anim.SetBool("isJumping", true);
}
}
and it doesn't work, the game runs just fine but the object does not change animation, someone knows why despite me following step by step the video? Thanks in advance.
Comment