Home > Enterprise >  Input.GetRawAxis Requesting a prefix why and where?
Input.GetRawAxis Requesting a prefix why and where?

Time:04-28

I'm making a top down movement system for my RPG game and its stating that I need the prefix ";" at the end of line 32 and 33. whats wrong with my code?

Error in Unity is:

Assets\PlayerController.cs(32,21): error CS1002: ; expected

Assets\PlayerController.cs(33,21): error CS1002: ; expected

Code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{

    public float moveSpeed;
    private Rigidbody2D rb;
    private float x;
    private float y;

    public Vector2 Input;

    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
        MovementInput();
    }
    private void FixedUpdate()
    {
        rb.velocity = input * moveSpeed;
    }
    void MovementInput()
    {
 32       float speed x = Input.GetAxisRaw("Horizontal", * Time.deltaTime);
 33      float speed y = Input.GetAxisRaw("Vertical", * Time.deltaTime);

        Input = new Vector2(x, y).Normalize;
    }
}

CodePudding user response:

I should be able to write an update method, thank you

   void Update()
 {
  float vertical = Input.GetAxis("Vertical");

  float horizontal = Input.GetAxis("Horizontal");

  transform.Translate(new Vector2(horizontal, vertical) * Time.deltaTime * speed);
 }

CodePudding user response:

You are trying to multiply a string

float speed x = Input.GetAxisRaw("Horizontal", * Time.deltaTime);

Instead, you need to do this:

float speedx = Input.GetAxisRaw("Horizontal") * Time.deltaTime;

You should receive the value from Input and AFTER THAT you need to multiply by delta time.

  • Related