2015-05-14 24 views
-2

我有用Unity3D C#編寫的代碼。問題是我有Unity 5,代碼是爲舊版本編寫的,所以有些東西我必須替換,因爲它們已經過時。隨着folloiwng代碼:替換小c犀利貶值

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: Property lockCursor has been deprecated. Use Cursor.lockState and Cursor.visible instead.'

如果我將與lockState取代lockCursor它無法正常工作。

如何正確更新過時的代碼?

+0

設法進行適當的替代自己,那麼如果它不後的代碼工作,你會得到幫助。 – Shar1er80

+0

你是什麼意思,「如果我將鎖lockCursor鎖lockCursor不工作。」? –

回答

0

如果你看一下在統一的網站,他們提到你應該什麼做替代。

嘗試以下操作:

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; 
    } 
} 
+0

是好的,但屏幕無法正常工作「不包含'visible'和'lockState''的定義」任何想法? – felix

+0

我的不好,應該是光標代替。嘗試一下 –

1

您應該使用枚舉insted的布爾值:

Cursor.lockState = CursorLockMode.Locked; 
Cursor.visible = false; 

在這裏您可以找到您可以設置可能的值: http://docs.unity3d.com/ScriptReference/CursorLockMode.html

+0

「不包含'visible'和'lockState''的定義」任何想法? – felix

+0

你使用Cursor類而不是Screen類嗎? –