2016-09-17 81 views
0

嘿傢伙我是新來的編碼,我正在努力工作這個簡單的代碼我需要此代碼連續循環運行5秒,而不會將其更新。雖然循環不工作代碼不runnign 60幀

void Update() { 

} 
void OnTriggerEnter2D(Collider2D other) 
{ 
    timer += Time.deltaTime; 
    if (other.gameObject.CompareTag("IcePickup")) 
    { 
     Destroy(other.gameObject); 

     Blade1 = GameObject.Find("Blade1"); 
     Blade1.gameObject.GetComponent<SpriteRenderer>().sprite = IceBlade; 

     int counting = 1; 
     while (counting <= 10) 
     { 
      print("icey"); 
      (Blade1.transform.Rotate(new Vector3(0, 0, -0.50f)); 
      counting ++; 
     } 
    } 
} 
+0

Blade1.transform.Rotate(new Vector3(0,0,-0.50f)); woops那裏應該沒有支架... –

+0

所以刀片正在旋轉的另一個腳本它會去0,0,-3.00f但是當我得到冰皮卡我試圖改變速度到-0.50f,但我不能解決它。 –

+0

編輯您的問題並通過更多信息進行更新 – Veltas

回答

1

好吧,也許這個例子可以幫助你:

using System; 

class Program 
{ 
    private static void Main(string[] args) 
    { 
     DateTime StartTime = DateTime.Now; 
     int Seconds = 5; 
     int Counter = 0; 

     while(DateTime.Now - StartTime < TimeSpan.FromSeconds(Seconds)) 
     { 
      //Your Code here? 
      Counter++; 
     } 

     Console.WriteLine("In " + Seconds + "seconds are " + Counter + "iterations"); 
    } 
} 

商祺!

+0

haha​​ wow非常感謝這個例子 –

0

不知道我是否理解這個問題 - 但是您的編碼循環數爲10。 10次​​迭代,而不是秒。這10次迭代可能需要3毫秒或一年或40納秒,這取決於該函數的速度。

很可能所有10次迭代都在第一幀顯示之前完成,這可能會解釋您的問題。

你不能簡單地編碼while很多秒;您需要質疑定時器設備並自行處理該標準。或者嘗試使用更大更大的迭代計數,直到找到需要大約5秒的約數。