- Home /
GettIng Error when trying to set a script to false
Hello, i have a script were im trying to make osme kind of pausemenu. Everything works but i really want it so the movement stops working when the game is paused. But when i try to set my movementscript to false, i get an error. "The name 'Movement' does not denote a valid type ('not found')."
Clearly it cant find the script, can soeone help me and tell me why it cant find it?
Thanks (:
#pragma strict
var PauseMenu : GameObject;
var mouseLook : Movement;
function Start ()
{
Screen.lockCursor =true;
}
function Update ()
{
if(Input.GetKeyDown(KeyCode.Escape))
{
var mouseLook = GameObject.Find("Player").GetComponent.<Movement>();
//HERE IS THE PROBLEM
mouseLook.enabled = !mouseLook.enabled;
//HERE IS THE PROBLEM
Time.timeScale = 0.0;
PauseMenu.SetActive (true);
Cursor.visible = true;
}
}
function BUTTONMainMenu ()
{
Application.LoadLevel("MainmenuScene");
}
function BUTTONExit ()
{
Application.Quit();
}
function BUTTONRETURN ()
{
Time.timeScale = 1.0;
PauseMenu.SetActive (false);
Cursor.visible = false;
}
We don't know anything about your project structure. Is everything named correctly? Is it in an Editor folder? Is the class name within that script correctly matching the file name?
Check that the $$anonymous$$ovement file exists and is placed on to the Player object.
Please post the content of your $$anonymous$$ovement.js file.
Answer by phil_me_up · Mar 22, 2016 at 08:12 PM
This isn't valid
var mouseLook = GameObject.Find("Player").GetComponent.<Movement>();
You probably want the below. I never use Javascript so may have got the syntax wrong.
var mouseLook = GameObject.Find("Player").GetComponent("Movement");
Check the docs for more info: http://docs.unity3d.com/ScriptReference/GameObject.GetComponent.html
Incorrect! TreyH said exactly the same thing a few days ago. That syntax is perfectly valid and is the JS equivalent of
GetComponent<$$anonymous$$ovement>(); // C#
GetComponent.<$$anonymous$$ovement>(); // In JS you add the extra dot
Answer by meat5000 · Mar 25, 2016 at 10:47 AM
The error occurs when the file "Movement" does not exist!
It is not even saying it cant find the component on the player. Its saying its not a valid Type. This means the class does not exist. This is easily proven by creating a new file called Movement.js. The error will go away straight away.
If you believe it does exist, open the Movement.js file and check that the Class name matches the filename exactly (although this may show a different error).
Your answer
Follow this Question
Related Questions
Troubleshooting the spawn mechanic in a puzzle game 1 Answer
Error in android manifest. Text as if encrypted. XML fails validation in the browser. 0 Answers
True False What am I doing wrong. 1 Answer
First time open error android game 0 Answers
"function DoRoll (Point, Axis, Angle, Duration)" Does Not Work on Android. Any reasons? 1 Answer