所以我正在使用 Unity 3d 游戏引擎制作游戏,而我正在使用WaitForSeconds
,但我会根据改变的内容遇到各种错误。这是我的代码(没有WaitForSeconds
):
using UnityEngine;
using System.Collections;
public class Attack : MonoBehaviour {
public int attack = 1;
public ParticleSystem MA;
// Use this for initialization
void Start () {
MA.enableEmission = false;
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown (KeyCode.E)){
attack++;
if(attack > 3){
attack = 1;
}
print (attack);
}
if(attack == 1){
if(Input.GetKeyDown (KeyCode.Q)){
print ("punch");
}
}
if(attack == 2){
if(Input.GetKeyDown (KeyCode.Q)){
/*if(Input.GetKeyDown (KeyCode.Q)){
WaitForSeconds magicdelay = new WaitForSeconds(1.0f);
yield return magicdelay;
/*MA.enableEmission = true;
yield return WaitForSeconds(1f);
MA.enableEmission = false;
}*/
print ("magic");
MA.enableEmission = true;
//I need help with the WaitForSeconds her
}
}
}
}
我多次尝试YieldInstruction WaitForSeconds = (int)1f;
,但这不起作用。求救!
答案 0 :(得分:0)
答案 1 :(得分:0)
if(Input.GetKeyDown (KeyCode.Q)){
StartCoroutine("Magic");
}
IEnumerator Magic(){
print ("magic");
MA.enableEmission = true;
yield return new WaitForSeconds(1.0f);
MA.enableEmission = false;
}
答案 2 :(得分:0)
这应该有效:
void Start ()
{
StartCoroutine (MyCoroutine ());
}
IEnumerator MyCoroutine ()
{
while(true)
{
Debug.Log(Time.time);
yield return new WaitForSeconds(1f);
}
}