【问题标题】:(42,18): error CS1525: Unexpected symbol `(', expecting `,', `;', or `='(42,18): 错误 CS1525: 意外符号 `(', 期望 `,', `;', 或 `='
【发布时间】:2020-01-14 00:48:32
【问题描述】:

我正在统一制作游戏,我将在其中制作时间系统。但我收到此错误“(42,18):错误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(){
        while (true){
            timeAdd();
            yield return new WaitForSendons(1);
        }
    }
}
}

什么会更好/根本?现在我收到错误“(42,18):错误CS1525:意外符号(', expecting,',;', or='”

感谢您的帮助。

【问题讨论】:

  • 该代码不会对我产生任何此类错误。我建议您在错误所在文件的第 42 行的第 42 行字符 18 处查找左括号。
  • 您投反对票的原因之一是因为我们在到达第 42 行之前不想计算行数。您应该让我们知道它是哪一行,也许可以在代码。
  • 好吧,我会的,谢谢

标签: c# unity3d


【解决方案1】:

文件末尾有一个不必要的}。只需将其删除!

【讨论】:

    【解决方案2】:
    IEnumerator time(){
        while (true){
            timeAdd();
            yield return new WaitForSendons(1);
        }
    }
    

    从“timeAdd()”中取出这个“time()”函数

    【讨论】:

      猜你喜欢
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多