I want to make an animation for the game. The following error occurred: NullReferenceException: Upravlenie.set_State (CharState value) (at Assets / Upravlenie.cs: 20). Here is the code:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Upravlenie : MonoBehaviour { public float horizontalSpeed; float speedX; public float verticalImpulse; Rigidbody2D rb; bool isGrounded; bool Running = false; private Animator animator; private CharState State { get { return (CharState)animator.GetInteger("State"); } set { animator.SetInteger("State", (int)value); } } void Start () { rb = GetComponent<Rigidbody2D>(); } private void Flip() { isFacingRight = !isFacingRight; Vector3 theScale = transform.localScale; theScale.x *= -1; transform.localScale = theScale; } public void LeftButtonDown() { speedX = -horizontalSpeed; if (isGrounded) State = CharState.Run; } public void RightButtonDown() { speedX = horizontalSpeed; if (isGrounded) State = CharState.Run; } public void Stop() { speedX = 0; } public void OnClickJump() { if (isGrounded) rb.AddForce(new Vector2(0, verticalImpulse), ForceMode2D.Impulse); if (!isGrounded) State = CharState.Jump; } void FixedUpdate() { transform.Translate(speedX, 0, 0); if (isGrounded) State = CharState.Idle; } private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Ground") isGrounded = true; } private void OnCollisionExit2D(Collision2D collision) { if (collision.gameObject.tag == "Ground") isGrounded = false; } } public enum CharState { Idle, Run, Jump } Soma animations EXACTLY done right
I need help interacting animation with code. Please help. PS Control made via Button buttons and added event triger component

