我目前正在做一個作業,我需要做一個作業鎖,我在unity中做(我是個新手,沒有太多的unity經驗)。我一直在遵循一個教程,但我認為我在某個地方出了問題。我不確定是什么原因,但我在提到旋轉的兩個例子中得到了錯誤。錯誤是 "在當前的環境中不存在'旋轉'這個名字",但就我所知,我已經完全按照教程的內容來做了。- 這個組合的代碼是這樣的:
using System.Collections;
using System.Collections.Generic;
public class LockControl : MonoBehaviour
{
private int[] result, correctCombination;
private void Start() {
result = new int[]{1,1, 1};
correctCombination = new int[] { 3, 7, 9 };
Rotate.Rotated = CheckResults;
}
private void CheckResults(string wheelName, int number) {
switch (wheelName)
{
case "wheel1"/span>:
result[0] = number;
break;
case "wheel2"/span>:
result[1] = number;
break;
case "wheel3"/span>:
result[2] = number;
break。
}
if (result[0] == correctCombination[0] & & result[1] == correctCombination[1] && result[2] == correctCombination[2] )
{
Debug.Log("打開了!")。
}
}
private void OnDestroy(){
Rotate.Rotated -= CheckResults;
}
而鎖定旋轉的代碼是這樣的:
using System.Collections;
using System.Collections.Generic;
public class RotateScript : MonoBehaviour
{
public static event Action< string, int> Rotated = delegate { };
private bool coroutineAllowed;
private int numberShown;
//Start在第一幀更新前被呼叫。
private void Start()
{
coroutineAllowed = true;
numberShown = 1;
}
private void OnMouseDown() {
if (coroutineAllowed)
StartCoroutine("RotateWheel")。
}
//Update每幀被呼叫一次。
private IEnumerator RotateWheel()
{
coroutineAllowed = false;
for (int i = 0; i <= 11; i ) {
transform.Rotate(0f, 0f, 3f) 。
yield return new WaitForSeconds(0。 01f)。
}
coroutineAllowed = true;
numberShown = 1;
if (numberShown > 9) {
numberShown = 0;
}
Rotated(name, numberShown);
}
}
錯誤出現在組合代碼中,我無法讓它作業。我已經嘗試了搜索,但我找不到答案,希望能在這里得到一些幫助,無論我是需要宣告什么,修正一個錯誤,還是僅僅從它的錯誤中重新開始。
謝謝!
uj5u.com熱心網友回復:
正如我在評論中提到的,我認為問題在于你對你所遵循的教程中的腳本進行了不當的命名。這個錯誤很直接的說,沒有任何東西用參考名稱Rotate來宣告。
為了解決這個問題,你需要將你的類和.cs檔案名都重命名為Rotate,或者更簡單的解決辦法,改變這幾行:
Rotate.Rotated = CheckResults;
Rotate.Rotated -= CheckResults;
to
RotateScript.Rotated = CheckResults;
RotateScript.Rotated -= CheckResults;
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/312433.html
標籤:
上一篇:如何保持兩個表的同步性
下一篇:Java中String陣列的排序
