【问题标题】:Unity recompile serialized scriptunity重新编译序列化脚本
【发布时间】:2019-11-27 18:54:58
【问题描述】:
我对 Unity 比较陌生,并试图从一个仅由 FPS 控制器和一些障碍物组成的简单场景开始。
作为控制器,我使用的是 Unity Standard Assets 中的控制器,一切正常。
然而,在添加角色网格后,我注意到我必须设置相机钳位。控制器脚本访问序列化的“MouseLook”脚本,我必须在其中编辑一些变量以满足我的需要。
由于它是序列化的,但是我不能简单地更改变量、保存代码并获取更改。
由于我不打算更改脚本已序列化的事实,因此我只想更新更改的变量。
我希望这是可以理解的。提前致谢!
【问题讨论】:
标签:
c#
unity3d
serialization
【解决方案1】:
您好,欢迎@Corneey,
对于初学者,我不知道如何重新编译该脚本或更改任何值(除了它可能具有的某些输入字段?),但有一个解决方法:
public class LookAtMouse : MonoBehaviour
{
//The object to rotate with/look at the mouse
public Transform target;
//Update is called once per frame
public void Update()
{
//Get mouse position in 3D space
Plane target = new Plane(Vector3.up, 0);
Ray r = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
//On the hit, rotate the target to the "impact point"
if(target.Raycast(r, out float distance)
Vector3 hitPoint = r.GetPoint(distance);
}
}