我使用C#为Unity3D编写代码。问题是我有Unity 5并且代码是为旧版本编写的,所以有些东西我必须更换,因为它们已经过时了。使用以下代码:
if (Input.GetMouseButton (1) && (!requireLock || controlLock || Screen.lockCursor))
// If the right mouse button is held, rotation is locked to the mouse
{
if (controlLock)
{
Screen.lockCursor = true;
}
rotationAmount = Input.GetAxis ("Mouse X") * mouseTurnSpeed * Time.deltaTime;
}
else
{
if (controlLock)
{
Screen.lockCursor = false;
}
}
我收到错误:
CS0618:
UnityEngine.Screen.lockCursor' is obsolete:
财产 lockCursor已被弃用。使用Cursor.lockState和 相反,Cursor.visible。'
如果我用lockState替换lockCursor则无效。
如何正确更新过时的代码?
答案 0 :(得分:1)
你应该使用枚举的布尔值:
audioTracks
您可以在此处找到可以设置的值: http://docs.unity3d.com/ScriptReference/CursorLockMode.html
答案 1 :(得分:0)
如果您查看Unity的网站,他们会提到您应该做的替代方案。
尝试以下方法:
if (Input.GetMouseButton (1) && (!requireLock || controlLock || Cursor.lockState == CursorLockMode.Locked))
// If the right mouse button is held, rotation is locked to the mouse
{
if (controlLock)
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
rotationAmount = Input.GetAxis ("Mouse X") * mouseTurnSpeed * Time.deltaTime;
}
else
{
if (controlLock)
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}