【问题标题】:How to use Handheld.Vibrate() for a series of vibrations? [duplicate]如何使用 Handheld.Vibrate() 进行一系列振动? [复制]
【发布时间】:2017-09-06 15:39:23
【问题描述】:

如何使用 Handheld.Vibrate() 进行一次以上的振动?

【问题讨论】:

标签: c# unity3d


【解决方案1】:

我猜你可以使用 Coroutines 做你想做的事:

void OnGUI()
{
    if (GUI.Button(new Rect(0, 10, 100, 32), "Vibrate!"))
        StartCoroutine( Vibrate() ) ;
}

private IEnumerator Vibrate()
{
     float interval = 0.05f ;
     WaitForSeconds wait = new WaitForSeconds(interval);
     float t ;

     for( t = 0 ; t < 1 ; t += interval ) // Change the end condition (t < 1) if you want
     {
         Handheld.Vibrate();
         yield return wait ;
     }

     yield return new WaitForSeconds(0.4f);

     for( t = 0 ; t < 1 ; t += interval ) // Change the end condition (t < 1) if you want
     {
         Handheld.Vibrate();
         yield return wait ;
     }
}

【讨论】:

  • 谢谢 Hellium,我会试试的。
猜你喜欢
  • 1970-01-01
  • 2020-11-05
  • 1970-01-01
  • 2017-10-24
  • 2017-01-16
  • 2018-05-21
  • 2022-09-23
  • 1970-01-01
  • 2023-03-20
相关资源
最近更新 更多