- Home /
How can I call Animations per C# Script?
I have an Animation Controller (I'll refer to it as Player_AnimController)
and 4 Animations (Player_Hurt, Player_Idle, Player_Jump and Player_Walk).
I have every Single Animation already set up, but what Lines of C# for Unity Code do I need to type in order to play Animations?
i got an email that you asked how you can set Boolean parameters, but i cant see that question here. Anyway I'll give an answer Heres a video tutorial
https://www.youtube.com/watch?v=q195HRyB_Aw
if you pause at 7:07 for instance you'll see when you open the animator controller tab, to the left of screen is a pull out menu that says "layers" and "parameters" just click parameters and then the little plus under it and there are different options for parameters you can choose but I think for beginning Booleans are the most straight forward.
Answer by laurenmhowie · Jul 08, 2018 at 05:58 PM
You can look in your animation controller and set boolean parameters for when the animations should play, from there turn the Boolean values true or false based on circumstances in your code attached to the player. That is how I have done it, but I am a beginner so there might be some other better or more common way(?) I'm not sure. Sorry if I sound a big confused because in truth I am but this here code worked for me!
public class freyawindwalk : MonoBehaviour {
public SpriteRenderer SR;
public Animator Animtor;
public bool cold = false;
public AnimationClip FreyaWindWalk;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other) {
if (other.CompareTag ("Freya")) {
Debug.Log ("FreyaEnter");
cold = true;
Animtor.Play("FreyaWindWalk");
}
}
}
Your answer
Follow this Question
Related Questions
How should I properly store statistics of various items of same type? 2 Answers
Multiple Cars not working 1 Answer
Multiple gameobjects but only one is screen wrapping. 0 Answers
Distribute terrain in zones 3 Answers
string/text database 0 Answers