我的脚本用于暂停和取消暂停游戏对象。我有两个相同的错误 (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/