Hi guys, New to coding trying to create player movement and these errors are showing up in unity -
Assets\Script\Movement.cs(16,26): error CS1061: 'Vector2' does not contain a definition for 'GetAxisRaw' and no accessible extension method 'GetAxisRaw' accepting a first argument of type 'Vector2' could be found (are you missing a using directive or an assembly reference?)
Assets\Script\Movement.cs(17,26): error CS1061: 'Vector2' does not contain a definition for 'GetAxisRaw' and no accessible extension method 'GetAxisRaw' accepting a first argument of type 'Vector2' could be found (are you missing a using directive or an assembly reference?)
How can I fix this?
Assets\Script\Movement.cs(16,26): error CS1061: 'Vector2' does not contain a definition for 'GetAxisRaw' and no accessible extension method 'GetAxisRaw' accepting a first argument of type 'Vector2' could be found (are you missing a using directive or an assembly reference?)
Assets\Script\Movement.cs(17,26): error CS1061: 'Vector2' does not contain a definition for 'GetAxisRaw' and no accessible extension method 'GetAxisRaw' accepting a first argument of type 'Vector2' could be found (are you missing a using directive or an assembly reference?)
How can I fix this?
PlayerMovement:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public float moveSpeed;
private bool isMoving;
private Vector2 input;
private void Update ()
{
if (!isMoving)
{
input.x = input.GetAxisRaw("Horizontal");
input.y = input.GetAxisRaw("Vertical");
if (input != Vector2.zero)
{
var targetPos = transform.position;
targetPos.x += input.x;
targetPos.y += input.y;
StartCoroutine(Move(targetPos));
}
}
}
IEnumerator Move(Vector3 targetPos)
{
isMoving = true;
while ((targetPos - transform.position).sqrMagnitude > Mathf.Epsilon)
{
transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
yield return null;
}
transform.position = targetPos;
}
}