【发布时间】:2017-12-06 03:52:09
【问题描述】:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
public class Movement : MonoBehaviour
{
//storage for the object's rigidbody
public Rigidbody2D rb2D;
//the public modifier for speed so i can edit from outside
public float speed;
//reliably take movements each second in an even, reliable manner.
void FixedUpdate()
{
//i move left and right if i use "a" or "d or "left" or "right"
float moveX = Input.GetAxis("Horizontal");
//I move up and down if i use "w" or "s" or "up" or "down"
float moveY = Input.GetAxis("Vertical");
//Vector inputs the move directions into a vector2 so i can move
Vector2 move = new Vector2(moveX, moveY);
rb2D.velocity = move * speed;
}
//following two methods are for the respective spikey builds
public void slow()
{
print("Shit, spike's got me!");
speed = .3f;
StartCoroutine(PauseTheSlowdown(2.1f));
speed = 1;
}
public void Bigslow()
{
print("HOLY CRAP THAT HURT");
speed = 0f;
StartCoroutine(PauseTheSlowdown(3.7f));
speed = 1;
}
IEnumerator PauseTheSlowdown(float seconds)
{
print("Pause this crap");
yield return new WaitForSecondsRealtime(seconds);
}
}
我在这里遇到了一个问题,我的代码似乎非常好。它运行,然后当外部脚本从任何一种尖峰方法中提取时,它的行为就像协程甚至不存在一样,并且从减速回到全速。 除了协程根本不会导致等待发生之外,没有任何错误或问题。我在这里遗漏了什么明显的东西吗?
【问题讨论】:
标签: c# unity3d coroutine ienumerator