【发布时间】:2020-10-27 19:06:47
【问题描述】:
我正在使用 Unity 2018.4.0f1 进行 Unity 入门课程。
出于某种原因,Unity 没有更新我的脚本,即使在 Visual Studio 上保存并在我的 Unity 脚本文件夹中正确显示之后也是如此。
这是我的 Unity 程序的 sn-p,显示正确。
但是,每当我进入播放模式时,属性都会重置为我在预更新脚本中的值。
我的程序很简单,因此我确定这不是软件问题。我还发现这里提出了类似的问题:
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);
}
}
【问题讨论】:
-
那是因为您之前修改了检查器中的值。如果您将资产序列化设置为文本模式,您也可以在 PlayerController.cs.meta 中看到修改。您可以右键单击您的属性并按重置以放弃更改,然后在脚本中更新您的值,也会在检查器中更新它们。
-
@EmanuelVintilă 是的,我之前确实在检查器中修改了值。如何让 Unity 再次使用我的脚本?
-
@EmanuelVintilă 实际上你能澄清一下你所说的财产是什么意思吗?你是说speed和turn这两个字段吗?
-
是检查器中显示的字段。你可以右键点击他们的名字,或者完全重置脚本。
-
@EmanuelVintilă 是的,我已经设法解决了。非常感谢。