(42,18):错误CS1525:意外符号(“,期望,'、;'或= [英] (42,18): error CS1525: Unexpected symbol (', expecting,', ;', or=
问题描述
我正在统一制作游戏,在这里我将建立一个时间系统.但是我收到此错误(42,18):错误CS1525:意外的符号(',期望,'、;'或='",我无法找出为什么我不想要工作.
I am making a game in unity, where i will make a time system. But im getting this error "(42,18): error CS1525: Unexpected symbol (', expecting,', ;', or='" and i can not find out why i doesnt want work.
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:意外符号(',期望,'、;'或or ='"
What would work better/at all? Right now im getting the error "(42,18): error CS1525: Unexpected symbol (', expecting,', ;', or='"
感谢您的帮助.
推荐答案
您已将time()函数嵌套在timeAdd()内,并且我假设您不支持C#7对本地函数的支持.将time()函数从timeAdd()中拉出,如下所示:
You've nested the time() function inside of timeAdd(), and I'm assuming you don't have C# 7 support for local functions. Pull the time() function out of timeAdd() to look like this:
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:意外符号(“,期望,'、;'或=的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!