- Home /
Question by
Timothy@Orikina · Jul 21, 2012 at 10:05 PM ·
mainmenu
JS Main menu issues?
Hey Unity! I'm new to Java Script and I am trying to make a Main Menu. Its not working, and I have never seen this error before. Please help.
Thanks in advance!
Code:
#pragma strict
var skin:GUISkin;
private var gldepth = -0.5;
private var startTime = 0.1;
var nativeVerticalResolution = 1200.0;
var scaledResolutionWidth = nativeVerticalResolution / Screen.height * Screen.width;
var mat:Material;
private var tris = 0;
private var verts = 0;
private var savedTimeScale:float;
private var pauseFilter;
private var showfps:boolean;
private var showtris:boolean;
private var showvtx:boolean;
private var showfpsgraph:boolean;
var lowFPSColor = Color.red;
var highFPSColor = Color.green;
var lowFPS = 30;
var highFPS = 50;
//var start : GameObject;
var url = "WebPlayer.html";
var statColor:Color = Color.yellow;
var GuiColor:Color = Color.white;
var credits:String[]=[
"Credits:",
"armedunity.com",
"bbb",
"aaa"] ;
var crediticons:Texture[];
enum Page { None,Main,Options,Credits,Play }
var currentPage:Page;
private var fpsarray:int[];
private var fps:float;
function EndPage() {
GUILayout.EndArea();
if (currentPage != Page.Main) {
ShowBackButton();
}
}
function ShowBackButton() {
if (GUI.Button(Rect(10,10,150,80),"Back")) {
currentPage = Page.Main;
}
}
function StatControl() {
GUILayout.BeginHorizontal();
showfps = GUILayout.Toggle(showfps,"FPS");
showtris = GUILayout.Toggle(showtris,"Triangles");
showvtx = GUILayout.Toggle(showvtx,"Vertices");
showfpsgraph = GUILayout.Toggle(showfpsgraph,"FPS Graph");
GUILayout.EndHorizontal();
}
function Qualities() {
switch (QualitySettings.currentLevel) {
case QualityLevel.Fastest:
GUILayout.Label("Fastest");
break;
case QualityLevel.Fast:
GUILayout.Label("Fast");
break;
case QualityLevel.Simple:
GUILayout.Label("Simple");
break;
case QualityLevel.Good:
GUILayout.Label("Good");
break;
case QualityLevel.Beautiful:
GUILayout.Label("Beautiful");
break;
case QualityLevel.Fantastic:
GUILayout.Label("Fantastic");
break;
}
}
function QualityControl() {
GUILayout.BeginHorizontal();
if (GUILayout.Button("Decrease")) {
QualitySettings.DecreaseLevel();
}
if (GUILayout.Button("Increase")) {
QualitySettings.IncreaseLevel();
}
GUILayout.EndHorizontal();
}
function BeginPage(width,height) {
scaledResolutionWidth = nativeVerticalResolution / Screen.height * Screen.width;
GUILayout.BeginArea(Rect(scaledResolutionWidth/2 - 2, nativeVerticalResolution/2 - 2,width,height));
}
function VolumeControl() {
GUILayout.Label("Volume");
AudioListener.volume = GUILayout.HorizontalSlider(AudioListener.volume,0.0,1.0);
}
private var toolbarInt:int=0;
private var toolbarStrings: String[]= ["Audio","Graphics","Stats","System"];
function ShowDevice() {
GUILayout.Label ("Unity player version "+Application.unityVersion);
GUILayout.Label("Graphics: "+SystemInfo.graphicsDeviceName+" "+
SystemInfo.graphicsMemorySize+"MB "+
SystemInfo.graphicsDeviceVersion+" "+
SystemInfo.graphicsDeviceVendor);
GUILayout.Label("Shadows: "+SystemInfo.supportsShadows);
GUILayout.Label("Image Effects: "+SystemInfo.supportsImageEffects);
GUILayout.Label("Render Textures: "+SystemInfo.supportsRenderTextures);
}
function Start () {
switch (currentPage){
case Page.Play: Play(); break;
case Page.Options: ShowToolbar(); break;
case Page.Credits: ShowCredits(); break;
}
}
//pages
function Play() {
BeginPage(600,600);
if(GUILayout.Button ("Campaign")) {
Application.LoadLevel("start");
}
EndPage();
}
function ShowCredits() {
BeginPage(600,600);
for (var credit in credits) {
GUILayout.Label(credit);
}
for (var credit in crediticons) {
GUILayout.Label(credit);
}
EndPage();
}
function ShowToolbar() {
BeginPage(800,250);
toolbarInt = GUILayout.Toolbar (toolbarInt, toolbarStrings);
switch (toolbarInt) {
case 0: VolumeControl(); break;
case 3: ShowDevice(); break;
case 1: Qualities(); QualityControl(); break;
case 2: StatControl(); break;
}
EndPage();
}
function update(){
if (GUILayout.Button ("Play")) {
currentPage = Page.Play;
}
if (GUILayout.Button ("Multiplayer")) {
Application.LoadLevel("mp");
}
if (GUILayout.Button ("Zombies To be added.")) {
//add zombies
}
if (GUILayout.Button ("Options")) {
currentPage = Page.Options;
}
if (GUILayout.Button ("Credits")) {
currentPage = Page.Credits;
}
if (GUILayout.Button ("Quit")) {
Application.Quit();
}
}
Error: Assets/Scripts/mainmenu.js(36,6): BCE0132: The namespace '' already contains a definition for 'Page'.
Comment
Answer by whydoidoit · Jul 21, 2012 at 10:07 PM
You have more than one thing called Page - perhaps you also have a script called Page in addition to the Enum called Page in the script you posted. You can only have one thing with the same name.
i second that, the error clearly says theirs already a page, try changing it to something else
Your answer
![](https://koobas.hobune.stream/wayback/20220613074520im_/https://answers.unity.com/themes/thub/images/avi.jpg)