- Home /
Public Class Error
I'm working on this script to make a day and night time system for our game. The problem is I get these errors in Unity's console "Assets/TimeOfDay.js(38,1): BCE0043: Unexpected token: public. " "Assets/TimeOfDay.js(38,18): BCE0043: Unexpected token: (. "
after each of my classes. Also I wanted to know what the best program is to edit scripts with . I tried setting Eclipse up with Unity but I got errors every time i coded with it. Also there was no syntex highlighting for Untitys JavaScript.
why does this site keep taking my classes out of the code?
///////////////////////////////////////////////////////////////////////////// /// /// This script will get time and set light status to day or night /// By Jared .S Chase /// 1/14/2011 /// /////////////////////////////////////////////////////////////////////////////
function Update () { var timeAccelerator = 3.0; // for now this is set to 3 until we extract user input from the settings / config menu var gameTime = Time.Time; // Time.Time returns time since you started playing. var acceleratedTime = gameTime * timeAccelerator;
if( acceleratedTime <= 4 )
{
Dawn() ; // set dawn class for time and height settings
}else if( acceleratedTime > 4 && acceleratedTime < 8 )
{
Morning(); // set morning class for time and light settings
}else if ( acceleratedTime > 8 && acceleratedTime < 12 )
{
Noon(); // set morning class for time and light settings
}else if ( acceleratedTime > 12 && acceleratedTime < 16 )
{
AfterNoon(); // set the after noon class for time and height
}else if ( acceleratedTime > 16 && acceleratedTime < 20 )
{
Evening(); // set the Evening class for time and hieght
}else if ( acceleratedTime > 20 && acceleratedTime <= 24 )
{
Night(); // set the Night class for time and height
}
}
// Create our classes for each time of day
public class Dawn() { }
public class Morning() { }
public class Noon() { }
public class AfterNoon() { }
public class Evening() { }
public class Night() { }
Answer by Peter G · Jan 15, 2011 at 02:03 PM
You don't seem to be using your classes correctly. You don't just call Dawn()
. Dawn is a class, not a method and you aren't doing anything by just saying Dawn()
so nothing will happen when you say that.
It looks like you actually want to use functions instead:
function Dawn () {
//Change your lighting and stuff.
}
or you could use an enum and a switch statement.
yea right now the classes are empty till the animator gives me the tag names of the items that will be edited. in the meantime im setting up the frame work .
why would I want to use a function ins$$anonymous$$d of a class?
yea this is my first time using JavaScript , normally I'm a Java / Pawn programmer .
and I would have used a switch statement ins$$anonymous$$d of so many if else's but i don't think you can with multiple conditions in the switch parameters in JavaScript can you?
If your a java programmer, then you should use C#, it will feel much more familiar to you. You would use a function because your current syntax is not correct, js will think what you are currently doing in the if statements is a method call, and that is probably why it is confused that you are defining it as a class further down.
wouldn't it be better to just use the class syntex correctly?
I don't know how you are setting up your frameworks, but if you just want to change a few settings, a method makes more sense to me because you can just call it once and be done with it.
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Trying to get enemy to aim at the player and shoot at it 2 Answers
Object reference not set to an instance of an object 1 Answer