为什么 input() 会出现前缀错误?

Why is the input() making a prefix error?

我一直在编写一个自上而下的游戏,我编写了基本的移动脚本,但在第 32 行它指出我需要在末尾添加一个前缀。

我该如何解决这个问题?

这是我得到的错误:

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();
    }
}

首先最好了解input.GetAxis()和input.GetAxisRaw()的异同。传入参数有两种: Vertical:获取垂直方向的值。 Horizo​​ntal:获取水平方向的值。 input.GetAxis()的return值为[-1, 1],具有平滑过渡功能的input.GetAxisRaw()的return值为{-1, 0 , 1}

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

}

希望能帮到你