- Home /
Error in a really short script
when using this it says: Assets/Scripts/pause atm.js(1,5): UCE0001: ';' expected. Insert a semicolon at the end. also this works on mobile too right?
bool isPaused;
void Start ()
{
isPaused = false;
}
void OnGUI ()
{
if (!isPaused)
{
if (GUI.Button(Rect(10,10,50,50), "Pause"))
{
Time.timeScale = 0f;
isPaused = true;
}
}
if (isPaused)
{
if (GUI.Button(Rect(10,10,50,50), "Play"))
{
Time.timeScale = 1.0f;
isPaused = false;
}
}
}
For future posts, please highlight your code and hit the 10101 button to format.
There's really no reason anyone should ever post a semi-colon or ) or { missing error to UA. There are a thousand of these already.
I don't know JS, but do you need "var" in front of bool?
this is C# and i see no using unity bla bla or class name. Please at least post whole script?
thats all there is here is where its from http://answers.unity3d.com/questions/424586/pause-and-restart-button-on-android.html
Answer by Berenger · Mar 26, 2014 at 11:20 PM
This is only the part of the code that answer the question, but you can't create a c# file and paste just that. Even more so if it's a js file. Have a look at how c# script is done. Basically, you need a class inheriting from monobehaviour, put your methods inside, and have the "using UnityEngine" at the top of the file, outside the class.
Answer by initTechsuport · Mar 29, 2014 at 02:29 PM
you are mixing C# and javascript, in c# it looks like this:
using UnityEngine;
using System.Collections;
public class PoolLib : MonoBehaviour {
bool isPaused;
void Start (){
isPaused = false;
}
void OnGUI (){
if (!isPaused){
if (GUI.Button(new Rect(10,10,50,50), "Pause")){
Time.timeScale = 0f;
isPaused = true;
}
}
if (isPaused){
if (GUI.Button(new Rect(10,10,50,50), "Play")){
Time.timeScale = 1.0f;
isPaused = false;
}
}
}
}