H
H
HnTR2019-06-14 22:31:33
Unity
HnTR, 2019-06-14 22:31:33

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

1 answer(s)
G
GavriKos, 2019-06-15
@HnTR

1) Wrap the code in the "code" tag - it's impossible to read.
2) Read the error carefully
3) Look for an instance of the "animator" class in your code, understand that it does not exist, and start it.
4) Do not get into the unit without knowledge of c #

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question