我想用一个协程来让玩家在拍摄新子弹之前等一会儿,但它永远不会超过收益率。代码如下Unity C#收益率返回新WaitForSeconds正在停止协程
protected override void Start() {
base.Start();
animator = GetComponent<Animator>();
score = GameManager.instance.playerScore;
playerLives = GameManager.instance.playerLife;
}
void Update(){
int horizontal = (int)Input.GetAxisRaw("Horizontal");
AttemptMove (horizontal, 0);
if (Input.GetKeyDown ("space")) {
if(canShoot){
Vector3 shootPosition = transform.position + new Vector3 (0, 0.5f, 0);
Instantiate (bullet, shootPosition, Quaternion.identity);
StartCoroutine(Shoot());
}
}
}
IEnumerator Shoot(){
Debug.Log("Start");
canShoot=false;
yield return new WaitForSeconds (shootingTimeDelay);
canShoot=true;
Debug.Log("End");
}
shootingTimeDelay设置为1.1f。我并没有在任何地方销毁我的gameObject,并且它可以在我的项目中的其他脚本中正常工作。
它从不打印结束。我没有得到什么错
'Time.timeScale'大于'0'? –
它等于1 –
这是c#上帝告诉你不使用协程 – MickyD