Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jchase520 · Jan 15, 2011 at 01:34 PM · javascripterrorclass

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() { }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 11 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jchase520 · Jan 15, 2011 at 02:06 PM 0
Share

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 .

avatar image jchase520 · Jan 15, 2011 at 02:09 PM 0
Share

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?

avatar image Peter G · Jan 15, 2011 at 02:19 PM 0
Share

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.

avatar image jchase520 · Jan 15, 2011 at 02:21 PM 0
Share

wouldn't it be better to just use the class syntex correctly?

avatar image Peter G · Jan 15, 2011 at 02:22 PM 0
Share

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.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges