(42,18):错误CS1525:意外的符号(',期待,',;'或=

时间:2017-12-08 22:57:36

标签: c# unity5

我正在制作一个团结的游戏,我将制作一个时间系统。但我得到这个错误“(42,18):错误CS1525:意外的符号(',期待,',;'或='”我无法找出为什么我不想工作。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TimeManager : MonoBehaviour {

    public int seconds = 0;
    public int minutes = 0;
    public int hours = 0;
    public int days = 0;
    public int year = 0;
    public Text TotalTimePlayed;

    void Start(){
        StartCoroutine(time());
    }

    void Update(){
        TotalTimePlayed = year + " Y" + days + " D" + hours + " H" + minutes + " M" + seconds + " S";
    }

    private void timeAdd(){
        seconds += 1;
        if(seconds >= 60){
            minutes = 1;
        }

        if(minutes >= 60){
            hours = 1;
        }

        if(hours >= 24){
            days = 1;
        }

        if(days >= 365){
            year = 1;
        }

        IEnumerator time() {  // Its in this line there is an error.
            while (true){
                timeAdd();
                yield return new WaitForSeconds(1);
            }
        }
    }
}

什么会更好/更好?现在我得到错误“(42,18):错误CS1525:意外的符号(',期待,',;',或='”

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

你已经在timeAdd()中嵌套了time()函数,我假设你没有C#7支持本地函数。将time()函数拉出timeAdd(),如下所示:

private void timeAdd(){
    seconds += 1;
    if(seconds >= 60){
        minutes = 1;
    }

    if(minutes >= 60){
        hours = 1;
    }

    if(hours >= 24){
        days = 1;
    }

    if(days >= 365){
        year = 1;
    }
}

IEnumerator time() {  // Its in this line there is an error.
    while (true){
        timeAdd();
        yield return new WaitForSeconds(1);
    }
}