- Home /
Question by
CustomStudios · Feb 27 at 07:41 PM ·
animationmovement
How to make a animated movement system
Hi so im new to coding but I was wondering how to make a working animated system.
This is what I have so far: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class AnimatedMovement : MonoBehaviour
{
public Animator anim;
// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown("w"))
{
anim.gameObject.GetComponent<Animator>().enabled = true;
anim.SetBool("IsWalking", true);
anim.SetBool("IsJumping", false);
}
if (Input.GetKeyDown("a"))
{
anim.gameObject.GetComponent<Animator>().enabled = true;
anim.SetBool("IsWalking", true);
anim.SetBool("IsJumping", false);
}
if (Input.GetKeyDown("s"))
{
anim.gameObject.GetComponent<Animator>().enabled = true;
anim.SetBool("IsWalking", true);
anim.SetBool("IsJumping", false);
}
if (Input.GetKeyDown("d"))
{
anim.gameObject.GetComponent<Animator>().enabled = true;
anim.SetBool("IsWalking", true);
anim.SetBool("IsJumping", false);
}
if (Input.GetKey("space"))
{
anim.gameObject.GetComponent<Animator>().enabled = true;
anim.SetBool("IsWalking", false);
anim.SetBool("IsJumping", true);
}
if (Input.anyKey == false)
{
anim.gameObject.GetComponent<Animator>().enabled = false;
}
}
}
It is a little messy and has a LOT of bugs.
Comment
Your answer
Follow this Question
Related Questions
Problem with collision detection during animation 1 Answer
Help Wanted. Switching localscale starts unwanted animation state. 1 Answer
Lerp or animate? 1 Answer
Mixamo strafing animation moving slightly on the Z-Axis 0 Answers
Can I animate objects/cameras in Update() without breaking Physics.Raycast? 1 Answer