首页 > 解决方案 > 我一直试图让我的 Unity 2D 播放器移动,但看起来我在脚本中犯了一个我找不到的错误

问题描述

我试图让我的 Unity 播放器移动。我开发了一个 2D 游戏并使用此脚本来尝试移动:



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

public class PlayerController : MonoBehaviour{

  public float speed;
  private Rigidbody2D rb;
  private Vector2 moveVelocity;

  void Start(){

    rb = GetComponent<Rigidbody2D>();


      }

  void Update(){
    Vector2.moveInput = new Vector2(Input.GetAxis("Horizontal"),Input.GetAxis("Vertical"));
    moveVelocity = moveInput.normalized * speed;

    }

  void FixedUpdate(){
    rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime);



    }

}

当我想打开统一时,总是有这个错误:

Assets\PlayerController.cs(19,13):错误 CS0117:“Vector2”不包含“moveInput”的定义

Assets\PlayerController.cs(20,20):错误 CS0103:当前上下文中不存在名称“moveInput”

我希望我能得到一些答案!谢谢!

标签: c#unity3d

解决方案


你在 和 之间加上Vector2句号moveInput

原来的:

Vector2.moveInput...

固定的:

Vector2 moveInput...

调用Vector2.moveInput假设该类Vector2有一个名为 的静态变量moveInput


推荐阅读