小编Ciu*_*sti的帖子

销毁对象中的Unity C# StartCoroutine()

我在带有 C# 的 Unity 中有这个脚本,协程的时间不工作,第二行forwardForce = 10f没有被调用:

using UnityEngine;
using System.Collections;

public class SlowPickup : MonoBehaviour
{
  public float waitTime = 2f;

  private IEnumerator DecreaseSpeed ()
  {
     GameObject.Find("Player").GetComponent<PlayerMovement>().forwardForce = 1f;
     yield return new WaitForSeconds(waitTime);
     GameObject.Find("Player").GetComponent<PlayerMovement>().forwardForce = 10f;
  }

  void OnTriggerEnter ()
  {
    Destroy(gameObject);
    StartCoroutine(DecreaseSpeed());
  }

}
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

3
推荐指数
1
解决办法
1713
查看次数

标签 统计

c# ×1

unity-game-engine ×1