(42,18): 错误 CS1525: 意外符号 (', expecting,', ;', or=
(42,18): error CS1525: Unexpected symbol (', expecting,', ;', or=
我正在统一制作一个游戏,我将在其中制作一个时间系统。但我收到此错误“(42,18): error CS1525: 意外符号 (', expecting,', ;', or='” 我无法找出为什么我不想工作。
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);
}
}
}
}
什么 better/at 全部有效?现在我收到错误“(42,18):错误 CS1525:意外符号(',期待,',;',或='”
感谢您的帮助。
您已将 time() 函数嵌套在 timeAdd() 中,我假设您没有对本地函数的 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);
}
}
我正在统一制作一个游戏,我将在其中制作一个时间系统。但我收到此错误“(42,18): error CS1525: 意外符号 (', expecting,', ;', or='” 我无法找出为什么我不想工作。
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);
}
}
}
}
什么 better/at 全部有效?现在我收到错误“(42,18):错误 CS1525:意外符号(',期待,',;',或='”
感谢您的帮助。
您已将 time() 函数嵌套在 timeAdd() 中,我假设您没有对本地函数的 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);
}
}