2016-09-17 82 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秒的约数。