Answer the question
In order to leave comments, you need to log in
Gives an error in unity, what should I do?
Assets\Player.cs(23,10): error CS0120: An object reference is required for the non-static field, method, or property 'Animator.SetInteger(string, int)' here is the error
Here is the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehavior
{
Rigidbody2D rb;
void Start()
{
rb = GetComponent();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
Jump();
}
if (Input.GetAxis("Horizontal") == 0)
{
Animator.SetInteger("Per", 1);
}
else
{
Animator.SetInteger("Per", 2);
}
}
void FixedUpdate()
{
rb.velocity = new Vector2(Input.GetAxis("Horizontal") * 12f, rb.velocity.y);
}
void Jump()
{
rb.AddForce(transform.up * 14f, ForceMode2D.Impulse);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question