【问题标题】:(31,16): error CS1525: Unexpected symbol `(', expecting `)', `,', `;', `[', or `='(31,16):错误 CS1525:意外符号 `(',需要 `)'、`,'、`;'、`[' 或 `='
【发布时间】:2016-09-11 21:56:35
【问题描述】:

我的脚本用于暂停和取消暂停游戏对象。我有两个相同的错误 (31,16):错误 CS1525: Unexpected symbol (', expecting)', ,',;', [', or='

我只是想暂停和取消暂停游戏对象。也许在我的场景中暂停和取消暂停更多。我需要游戏对象暂停几秒钟然后取消暂停。不要通过按键暂停游戏对象。这是我的脚本:

    using UnityEngine;
using System.Collections;

public class star : MonoBehaviour {
GameObject[] pauseObjects;


    void Start () {
    pauseObjects = GameObject.FindGameObjectsWithTag("Player");
    }

void Pause(){
  StartCoroutine(waitToUnpause);
}

IENumerator waitToUnpause(){
  //do the thing to pause game
  Time.timeScale = 7f;//or some other method
  yield return new WaitForSeconds(7);///or any duration you want
  Time.timeScale = 1f;//or some other method
}

void pauseGameobject()

{
 timeLeft -= Time.deltaTime;
if(timeLeft < 0)
gameObject.SetActive(false);
{

start coroutine("wait");

}

}

public ienumenator wait()

{

time.timescale = 0;

yield return new waitforsceonds(7);

time.timesale = 1;

}
void pauseGameobject()

{

if(timerleft < 0)

{

start coroutine("wait");

}

}

public ienumenator wait()

{

time.timescale = 0;

yield return new waitforsceonds(7);

time.timesale = 1;

}

}

【问题讨论】:

  • 你复制了那个代码吗?如果是这样,除了那些你得到意想不到的符号东西的语法错误之外,你还有一些语法错误。例如。在pauseGameobject 中,gameObject.SetActive(false) 应该在{ 之后,而不是之前(在 if 内)。还有一些东西,比如错误的大写/小写或不应该出现的空格。
  • 如果这不是确切的代码,请从文件中复制并插入,您可以使用 stackoverflow 代码命令({}-图标),以及适当的缩进和相应的行号错误(因此我们不必计算更长的代码)会有所帮助。
  • 我以为我做到了。
  • 你能测试一下代码吗?
  • 嗯,如前所述,仅通过查看您发布的代码,我就可以看出它无法编译的原因有很多(语法错误)。

标签: android css unity3d compiler-errors unityscript


【解决方案1】:

这段代码编译时没有错误(你的代码很漂亮……不干净)。但它肯定行不通。我还更改了一些命名以匹配命名约定(小写/大写)。

using UnityEngine; 
using System.Collections;

public class Star : MonoBehaviour {
    GameObject[] pauseObjects;

    // I guess this variable is meant to be a field
    // it is never set to any initial value!
    float timeLeft;

    void Start () {
        pauseObjects = GameObject.FindGameObjectsWithTag("Player");
    }

    void Pause(){
        StartCoroutine(WaitToUnpause());
    }

    IEnumerator WaitToUnpause(){
        //do the thing to pause game
        Time.timeScale = 7f;//or some other method
        yield return new WaitForSeconds(7);///or any duration you want
        Time.timeScale = 1f;//or some other method
    }

    void PauseGameobject()

    {
        timeLeft -= Time.deltaTime;
        if(timeLeft < 0)
        {

            gameObject.SetActive(false);
            StartCoroutine(Wait());

        }

    }

    public IEnumerator Wait()

    {

        Time.timeScale = 0;

        yield return new WaitForSeconds(7);

        Time.timeScale = 1;

    }

// The following code is nearly a duplicate of the above two functions

//  void PauseGameobject()
//
//  {
//
//      if(timeleft < 0)
//
//      {
//
    //          StartCoroutine(Wait());
//
//      }
//
//  }
//
//  public IEnumerator Wait()
//
//  {
//
//      Time.timeScale = 0;
//
//      yield return new WaitForSeconds(7);
//
//      Time.timeScale = 1;
//
//  }

}

【讨论】:

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