Hello,
I am new to using Unity and I have came across a problem with a piece of code I have written for my RPG game. This code is meant to allow the character to move but when I click play it comes up with error CS0120. I was maybe wandering if you could look at my code and see what is wrong with it.
Thanks,
P.S I understand it’s quite a simple code but i’m new
using UnityEngine;
using System.Collections;
public class Playermovement : MonoBehaviour {
Rigidbody2D rbody;
Animator anim;
// Use this for initialization
void Start () {
rbody = GetComponent<Rigidbody2D> ();
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
Vector2 movement_vector = new Vector2 (Input.GetAxisRaw ("Horizontal"), Input.GetAxisRaw ("Vertical"));
if (movement_vector != Vector2.zero) {
UnityEngine.Animator.SetBool ("iswalking", true);
anim.SetFloat("input_x",movement_vector.x);
anim.SetFloat("input_y",movement_vector.y);
} else {
UnityEngine.Animator.SetBool ("iswalking", false);
}
rbody.MovePosition (rbody.position + movement_vector * Time.deltaTime);