CS1061 Unity Error

Zetsy

New member
Joined
Jun 10, 2021
Messages
1
Programming Experience
Beginner
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?

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;
 }
}
 
Why exactly do you think that the Vector2 class does have a GetAxisRaw method? I've never used Unity but, as far as I can tell, the error message is spot on and the only GetAxisRaw method is a static member of the Input class. Example 5 here uses both the Vector2 class and the Input.GetAxisRaw method. If I could find that information, which I did by simply searching the web for "unity getaxisraw", then you should have been able to as well.
 
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?

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;
 }
}
Change the input.GetAxisRaw to Input.GetAxisRaw
 
Back
Top Bottom