c# - 为什么 Unity 不更新脚本?
问题描述
我正在使用 Unity 2018.4.0f1 进行 Unity 入门课程。
出于某种原因,Unity 没有更新我的脚本,即使在 Visual Studio 上保存并在我的 Unity 脚本文件夹中正确显示之后也是如此。
这是我的 Unity 程序片段,它正在正确显示。
但是,每当我进入播放模式时,属性都会重置为我在预更新脚本中的值。
我的程序很简单,因此我确定这不是软件问题。我还发现这里提出了类似的问题:
https://forum.unity.com/threads/why-is-unity-not-updating-my-scripts.497383/
以及这里:
https://answers.unity.com/questions/17460/unity-is-not-updating-my-scripts.html
这些都不包含一个决定性的答案,我无法解决这个问题。
我的完整程序如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed = 10.0f;
public float turn = 25.0f;
public float horizontalInput;
public float verticalInput;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
horizontalInput = Input.GetAxis("Horizontal");
verticalInput = Input.GetAxis("Vertical");
// We'll move the player forward
transform.Translate(Vector3.forward * Time.deltaTime * speed * verticalInput);
transform.Rotate(Vector3.up, Time.deltaTime * turn * horizontalInput);
}
}
解决方案
当您有也被序列化的公共变量时,来自编辑器的值会覆盖脚本中声明的值,您可能必须删除场景的一些元数据才能完全重置它。只需从编辑器更改它,或将这些值设为私有,然后编辑器将无法访问它们并且不会更改值
推荐阅读
- python - 安装 PIP 时收到语法错误
- ruby-on-rails - 在一个视图中将数据从多个表单保存到多个模型的问题
- sapui5 - SAP HCM 公共控制器 PersInfoWrapperController
- android - 如何使用 XML 制作翻转动画
- r - 使用 lubridate 解析具有 mm/dd/yyyy 0:00:00 格式的日期时如何修复错误
- python - pandas groupby 与 pyspark groupby 不一样
- excel - 在 VBA/Excel 中将列标题转换为组合框的列表条目
- reactjs - 如何在另一个组件的函数中渲染反应组件?
- android - Android:如何使用 Retrofit 在所有 url 的末尾添加一些东西?
- java - 在Hashmap中搜索字符串数组的有效方法