- Home /
Can't use script name as variable type?
I am fixing a bug that my game has. The bug is that when the game is paused, some scripts are disabled (specifically camera orbiting ones), but if you click on a brick(programmed to disable the same scripts when being dragged), the camera orbit disabling scripts are enabled even though it is in pause mode because of an OnMouseUp function.
When trying to fix the bug with a boolean in the pause menu script(C#), and I need to change that boolean from the camera orbit script(js). But I get the following similar errors:
Assets/disableMouseOrbit.js(13,71): BCE0005: Unknown identifier: 'PauseMenu'.
and
Assets/disableMouseOrbit.js(22,41): BCE0005: Unknown identifier: 'PauseMenu'.
Here are my scripts (sorry if they are messy):
Pause Menu:
using UnityEngine;
using System.Collections;
public class pauseMenu : MonoBehaviour {
public bool paused = false;
bool isButtonVisible = true;
Rect buttonRectangle = new Rect(100, 100, 100, 50);
public MouseOrbit mouseOrbitScript;
public PartMenu partMenu2;
void Start()
{
mouseOrbitScript = Camera.main.GetComponent<MouseOrbit>();
}
void Update () {
if(Input.GetKeyUp(KeyCode.Escape) && paused == false)
{
paused = true;
isButtonVisible = false;
Time.timeScale = 0;
mouseOrbitScript.enabled = false;
GetComponent<PartMenu>().enabled = false;
}
else if(Input.GetKeyUp(KeyCode.Escape) && paused == true) {
paused = false;
mouseOrbitScript.enabled = true;
isButtonVisible = true;
Time.timeScale = 1;
GetComponent<PartMenu>().enabled = true;
}
}
void OnGUI ()
{
if ( isButtonVisible ) {
if ( GUI.Button(buttonRectangle, "Turn Me Off") ) {
isButtonVisible = false;
}
}
}
}
Disable Camera Orbit:
var mouseOrbitScript : MouseOrbit;
var pauseMenuScript : GameObject;
function Start()
{
mouseOrbitScript = Camera.main.GetComponent(MouseOrbit);
GetComponent(Rigidbody).transform.rigidbody.isKinematic = true;
}
function OnMouseOver ()
{
if(Input.GetKeyDown(KeyCode.Mouse0)&&pauseMenuScript.GetComponent(PauseMenu).paused == false)
{
mouseOrbitScript.enabled = false;
GetComponent(Rigidbody).transform.rigidbody.isKinematic = false;
}
}
function OnMouseUp()
{
if(pauseMenuScript.GetComponent(PauseMenu).paused == false){
mouseOrbitScript.enabled = true;
GetComponent(Rigidbody).transform.rigidbody.isKinematic = true;
}
}
There may still be bits of code that were from previous attempts to fix the bug, please point them out if you see any.
Answer by billykater · Nov 30, 2013 at 11:07 AM
The first issue really was the different casing, as iwaldrop already mentioned. Always remember that all programming languages in unity are case sensitive when it comes to variable/class names.
The second problem is that you are mixing c# and unityscript and want to reference one from the other. I suggest you read up on the compilation order of unity: http://docs.unity3d.com/Documentation/Manual/ScriptCompileOrderFolders.html. This way you can fix the problem.
Though in the long run I strongly discourage you from using more than one language as you can only fix it for one way (either c# -> unityscript or unityscript -> c#). You will most probably run into several errors of this kind as you project grows.
Answer by iwaldrop · Nov 30, 2013 at 08:58 AM
It looks a lot to me like you've named the pause menu script 'pauseMenu' instead of 'PauseMenu'. Classes should always start with an uppercase letter.
public class pauseMenu : MonoBehaviour
I changed the name and class declaration, but still no luck
Your answer
Follow this Question
Related Questions
Disable JS from C# 1 Answer
Multiple Cars not working 1 Answer
Disable script does not work 1 Answer
Sending the C# function parameter to JS function. 1 Answer
Distribute terrain in zones 3 Answers