我一直在撰寫一個自上而下的游戲并撰寫了基本的移動腳本,但在第 32 行它指出我需要在末尾添加一個前綴。
我怎樣才能解決這個問題 ?
這是我得到的錯誤:
Assets\PlayerController.cs(32,71): 錯誤 CS1003: 語法錯誤, ',' 預期
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();
}
}
uj5u.com熱心網友回復:
首先,最好了解 input.GetAxis() 和 input.GetAxisRaw() 的異同。傳入引數有兩種型別: Vertical:獲取垂直方向的值。Horizo??ntal:獲取水平方向的值。input.GetAxis() 的回傳值為 [-1, 1],具有平滑過渡功能的 input.GetAxisRaw() 的回傳值為 {-1, 0, 1}
private void GetInput()
{
float move = Input.GetAxis("Horizontal");
if(move != 0){
Vector2 input = new Vector2(move * Time, rb.velocity.y);
}
}
希望能幫到你
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/466796.html
