Home > database >  Why is the input() making a prefix error?
Why is the input() making a prefix error?

Time:04-28

I've been coding a top down game and I wrote the basic movement scripts but on line 32 it states that I need a prefix at the end.

How can I fix this ?

Here is the error I get:

Assets\PlayerController.cs(32,71): error CS1003: Syntax error, ',' expected

using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{

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

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

    // Update is called once per frame
    void Update()
    {
        GetInput();
    }
    private void FixedUpdate()
    {
        rb.velocity = input * moveSpeed;
    }
    private void GetInput()
    {
        Vector2 input = new Vector2(input.GetAxisRaw("Horizontal"), 0 input.GetAxisRaw("Vertical"));
        input.x = x;

        input.Normalize();
    }
}

CodePudding user response:

First of all, it is best to understand the similarities and differences between input.GetAxis() and input.GetAxisRaw(). There are two types of incoming parameters: Vertical: Get the value in the vertical direction. Horizontal: Get the value in the horizontal direction. The return value of input.GetAxis() is [-1, 1], and the return value of input.GetAxisRaw() with smooth transition function is {-1, 0, 1}

 private void GetInput()
 {
    float move = Input.GetAxis("Horizontal");
    if(move != 0){
       Vector2 input = new Vector2(move * Time, rb.velocity.y);
    }

}

Hope can help you

  • Related