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 Blam556 · Feb 01, 2012 at 08:45 PM · javascriptuce0001

Dreaded UCE0001 ';' error

Hello UnityAnswers,

As a generally new programmer I am still stumbling upon sites to help me with my school work and get useful tips,tricks, and incite to sharpen my skills but it's hard when you drop face first into an error you cant seem to fix.

 `using UnityEngine;
 using System.Collections;
 
 var gun1 = GameObject;
 gun1 = GameObject.Find("Box02");
 var gun2 = GameObject;
 gun2 = GameObject.Find("ak47");
 
 function Start() {
 }
 
 function Update() {
 
 if (Input.GetButtonDown('1')) {
 gun2.SetActiveRecursively(false);
 gun1.SetActiveRecursively(true);
 
 }
 }`

a reeeally simple weapon switching script will come from what I have so far but not if I cant get passed "(1,6): UCE0001: ';' expected. Insert a semicolon at the end." I says I do not have a semi-Colon at the end of my first line, but like so many scripts before me it clearly does. Reading through other forum posts from many different sites I have seen that it could be a formatting or syntax error, only a few weeks into unity itself I am not FULLY adjusted to its syntax and could be missing something very obvious. Any help would be Bueno!

Thanks for your time.

Comment
Add comment · Show 6
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 Blam556 · Feb 02, 2012 at 01:33 AM 0
Share

Thank you for the detailed reply! hmmm alright, I switched things around a bit but am still getitng the same error on the same line. The two items that are getting found are childes of the Firstpersoncontroler>$$anonymous$$aincamera>Weapons>Box02,ak47. I dont know if that would cause problems or if I called it wrong because of that fact?

 using UnityEngine;
 using System.Collections;
 
 var gun1 : GameObject;
 var gun2 : GameObject;
 
 
 function Start() 
 {
 gun1 = GameObject.Find("Box02");
 gun2 = GameObject.Find("ak47");
 }
 
 function Update() {
 
 if (Input.GetButtonDown('1')) {
 gun2.SetActiveRecursively(false);
 gun1.SetActiveRecursively(true);
 
 }
 }
avatar image SisterKy · Feb 02, 2012 at 01:48 AM 0
Share

I know it's tempting because the buttons are labeled so poorly, but please don't post updates to your question as an answer...

(btw, it doesn't give you the line for no reason at all; though the problem is often not exactly at the given point, it does give a hint as to what might be wrong. So it usually makes sense to give the information here.)

avatar image SisterKy · Feb 02, 2012 at 01:48 AM 0
Share

No, hirarchy-quirks can't lead to syntax-errors, but only to runtime-errors.

avatar image SisterKy · Feb 02, 2012 at 02:00 AM 0
Share

Hint: Not sure how much actual value this list has, but maybe you can get something out of it...? http://answers.unity3d.com/questions/155200/stuff-is-going-wacky-checklist-compiler-errors-syn.html

avatar image Blam556 · Feb 02, 2012 at 04:33 AM 0
Share

Ahhh Thank you for all your help!

I will continue to work through this and figure out the rest! Thank you again.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by SisterKy · Feb 01, 2012 at 08:50 PM

I'll assume the ' at the start and end are only here, not in your actual script... (you'd have to remove them)
Anyway, here's what I see:

 var gun1 = GameObject;

I think you don't want to put a non-existent thing called "GameObject" inside your new variable; instead, you want to set the type; what kind of variable this is going to be. You do that with a colon instead of a equal-sign

 var gun1 : GameObject;

also, you need to do the

 gun1 = GameObject.Find("Box02");

inside of a function.
If you create a new value (like a number or a string) it's completely legal to do it the way you did.
But GameObjects work a bit different, so as a rule of thumb: If you assign a GameObject - whether you instantiate it in the script or take it from the scene (as you do here) - do it inside a function.
Preferably inside

 function Start () {}
 

You could also consider

 function Awake () {}

provided, that "Box02" is already in the scene when the game starts.
Function Awake gets called before anything else at the very beginning of the game and should be used to set things up. But if you might later choose to instantiate "Box02" at runtime by a different script - even if you do it in function Awake also, this other script might get called after this script and the Find would turn out empty and you'd get a nullreferenceexception... so probably better do it in Start...

Well, that's what I see at first glance... I'm not sure, however, if that will fix your problem...

Comment
Add comment · 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
0

Answer by SisterKy · Feb 05, 2012 at 11:48 AM

I think I have an idea what's causing the problem. Sometimes I don't see the wood because of all the trees.....
What language are you using? the 'using' commands are C# and I think they are illegal in .js; the syntax for variable-declaration is javascript. So check the filename-extension and adjust accordingly.
If it's C# you need to wrap everything except for 'using' inside

 public class NameOfYourFile : MonoBehaviour {}

and change variable-declaration-syntax to

 private GameObject gun1;

'private' is the right here, because you 'Find' the ObjectReference; If you wanted to drag-and-drop the reference in the Editor instead, it would need to be 'public' (if I'm not misstaken)

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

attract particles 3 Answers

Every 0.5 sec there is a 10% chance of a target spawning. 2 Answers

How can I make a function wait before it starts running again? 1 Answer

help unity3d javascript 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