- Home /
CS8085 Parsing Error?
I am getting the error:
The first line is always the one getting the error. "var defaultCam : Game Object;" Is the 4th line. Here is my code:
var defaultCam : GameObject;
var playerObject : GameObject;
var isEnabled : boolean;
var shift : boolean;
var ctrl : boolean;
var accelerationAmount : float = 3;
var accelerationRatio : float = 1;
var slowDownRatio : float = 0.5;
var flySpeed : float = 0.5;
function Update()
{
if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift))
{
shift = true;
flySpeed *= accelerationRatio;
}
if (Input.GetKeyUp(KeyCode.LeftShift) || Input.GetKeyUp(KeyCode.RightShift))
{
shift = false;
flySpeed /= accelerationRatio;
}
if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl))
{
ctrl = true;
flySpeed *= slowDownRatio;
}
if (Input.GetKeyUp(KeyCode.LeftControl) || Input.GetKeyUp(KeyCode.RightControl))
{
ctrl = false;
flySpeed /= slowDownRatio;
}
if (Input.GetAxis("Vertical") != 0)
{
transform.Translate(-defaultCam.transform.forward * flySpeed * Input.GetAxis("Vertical"));
}
if (Input.GetAxis("Horizontal") != 0)
{
transform.Translate(-defaultCam.transform.right * flySpeed * Input.GetAxis("Horizontal"));
}
if (Input.GetKey(KeyCode.E))
{
transform.Translate(defaultCam.transform.up * flySpeed*0.5f);
}
else if (Input.GetKey(KeyCode.Q))
{
transform.Translate(-defaultCam.transform.up * flySpeed*0.5f);
}
if (Input.GetKeyDown(KeyCode.F12))
switchCamera();
if (Input.GetKeyDown(KeyCode.M))
playerObject.transform.position = transform.position; //Moves the player to the flycam's position. Make sure not to just move the player's camera.
}
function switchCamera()
{
if (!isEnabled) //means it is currently disabled. code will enable the flycam. you can NOT use 'enabled' as boolean's name.
{
transform.position = defaultCam.transform.position; //moves the flycam to the defaultcam's position
defaultCam.camera.active = false;
this.camera.active = true;
isEnabled = true;
}
else if (isEnabled) //if it is not disabled, it must be enabled. the function will disable the freefly camera this time.
{
this.camera.active = false;
defaultCam.camera.active = true;
isEnabled = false;
}
}
Can anyone help me here on why? I am using a script I found here:
defaultCam is a camera so it should be declared as one, not as a GameObject. Like :
public var defaultCam : Camera;
Your code does not generate a compiler error for me, but the warnings are something you might want to deal with. For example, line 60 should be:
defaultCam.SetActive(false);
@ $$anonymous$$r Soad No that's not the problem, if I place that line of code at the bottom of all the variables the first line is always the one getting the error. I need to paste this in a JS file. Cause this is in a C# file.
Answer by Kiwasi · Nov 10, 2014 at 03:05 AM
This is JavaScript written inside a C# script file. Copy this into a .js file and it should work fine.
Parsing error is the error thrown when the compiler can't figure things out and gives up.
I haven't tried this yet, but now that I look more closely i should have known that function is for JS and void is for C#. I'm going to try this! Thx!
Your answer
![](https://koobas.hobune.stream/wayback/20220613171128im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
What parsing errors do i have 1 Answer
monodevelop 4.0.1 run with empty 0 Answers
How to use ArrayList.IndexOf and Conver.ToInt32 1 Answer
Can I call a js script method inside a C# dll project? 1 Answer