【发布时间】:2019-06-04 19:51:52
【问题描述】:
我正在尝试在 Unity 中制作一个平台跳跃游戏,当你死后,游戏应该在文本上显示游戏,然后等待 3 秒。但我得到了这些错误:
error CS1525: Unexpected symbol `(', expecting `,', `;', or `='
error CS1525: Unexpected symbol `IEnumerator'
我的代码是:
using UnityEngine;
using System;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed = 1700.0f;
public GameObject Player;
public Text TheText;
void Start()
{
TheText.text = "";
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
GetComponent<Rigidbody>().AddForce(movement * speed * Time.deltaTime);
IEnumerator Wait1()
{
if (Player.transform.position.y < -100.59)
{
TheText.text = "You Lost. Try Again!!";
yield return new WaitForSeconds(5);
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
IEnumerator Wait2()
{
if (Player.transform.position.y > 210)
{
TheText.text = "You Lost. Try Again!!";
yield return new WaitForSeconds(5);
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
theres 4 more of those, they're all the same
我希望它在重新启动游戏之前等待,但我收到了这些错误。 void fixedupdate(); 语句给出以下错误
cannot be an iterator block because 'void' is not an iterator interface type.
【问题讨论】:
-
或许指出错误与哪些代码行有关?
标签: c# unity3d ienumerator