c# - 我一直试图让我的 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”
我希望我能得到一些答案!谢谢!
解决方案
你在 和 之间加上Vector2
句号moveInput
。
原来的:
Vector2.moveInput...
固定的:
Vector2 moveInput...
调用Vector2.moveInput
假设该类Vector2
有一个名为 的静态变量moveInput
。
推荐阅读
- javascript - 在 ASP.NET Razor 视图中对大量对象进行分页
- symfony - Symfony 5 pb 与存储库
- javascript - 数组和 JSON 之间是否存在混合数据结构?
- python - 如何在 Tkinter 画布上隐藏图像?
- javascript - 我如何验证而不需要刷新页面?
- python - 如何下载 pypi 中不再存在的旧版本的 tar.gz 文件?
- docker - ddev + elasticsearch 最新版本的问题
- ios - 带有 2 个部分选择的 UITableview
- c# - 如何检测连接请求是否来自现有连接的客户端?
- android - 如何使用背景和图标创建 android drawable xml 状态
(svg)