android - (31,16) : error CS1525: Unexpected symbol `(' , 期望 `)' 、 `,' 、 `;' 、 `[' 或 `='

标签 android css unity-game-engine compiler-errors unityscript

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

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

    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;

}

}

最佳答案

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

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;
//
//  }

}

关于android - (31,16) : error CS1525: Unexpected symbol `(' , 期望 `)' 、 `,' 、 `;' 、 `[' 或 `=',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39441022/

相关文章:

java - Android Studio 在重新启动时显示错误

performance - 缓存视频背景

html - 带有文本与图像的 Div 的 CSS 位置/尺寸

javascript - IE7/8 不动态添加 css 属性 'top' 作为内联样式

c# - 修复了 Unity 中的 ScrollRect 多点触控问题?

c# - JSONObject 中每个 JSONnode 的 Unity

android - 在不使用 C++ 的情况下使用 Unity 或 Java 在 Vuforia 中进行图像检测

java - 在java中的线程和标志之间交换多个对象

android - 在第 3 方应用程序中重用默认的 android 联系人搜索 - 可能吗?

android - 在 Android Navigation Architecture 中,如何检查当前 Fragment 是否是最后一个?