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 Zenrati · May 17, 2015 at 06:37 PM · javascripterrorcollidergame

Javascript error.. insert semicolon??

Hey, thank's for reading. I am currently making a script in Unity 5 with Javascript, and there is an error, and I cannot figure out what's wrong with my script.

Here's the error:

Assets/Standard Assets/HorrorGameStuffs/DreamshardsLab.js(27,26): UCE0001: ';' expected. Insert a semicolon at the end.

And here is the script:

  var Dreamshard : int = 0;
  var dreamshardsToWin : int = 2;        //number to win!
  var win = false;
  
  function Start()
  {
      win = false;
  }
  
 //Saying if you have 'x' dreamshards, the 'win' state is applied.
   function Update ()
  {
      if (Dreamshard == dreamshardsToWin) 
      {
          win = true;
      }
          
     }  //trying to say that if win state, then upon entering zone, next level loaded.
        if (win == true)
      {
          function (OnTriggerEnter)
          {
              if (other.gameObject.tag == "ExitLab")
              {
                  Application.loadedLevel("MainMenu");
              }
        } ***//Line 27***
      }            
  
  
  
  
  function OnTriggerEnter( other : Collider )
   {
         if (other.gameObject.tag == "Dreamshard")
         {
                  Dreamshard += 1;
                  Debug.Log("A dreamshard was picked up. Total shards = " + Dreamshard);
                  Destroy(other.gameObject);
          }
   }
  
  function OnGUI()
  {
      if (Dreamshard < dreamshardsToWin)
      {
          GUI.Box(Rect((Screen.width/2)-100, 10, 200, 35), "" + Dreamshard + " Dreamshards");
      }
      else
      {
          GUI.Box(Rect((Screen.width/2)-100, 10, 200, 35), "Find the exit.");
      }
  }




When I double-click the error, it redirects me to line 27 (I've marked it for you). I honestly have no idea why it would want me to add a semicolon.. Please help. Thank you so much for your time.

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

2 Replies

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

Answer by Eno-Khaon · May 17, 2015 at 07:23 PM

Also, the formatting itself is a little wonky.

 if (win == true)
 {
     function (OnTriggerEnter) // Not good
     {
         if (other.gameObject.tag == "ExitLab")
         {
             Application.loadedLevel("MainMenu");
         }
     }
 }

Like tanoshimi stated, this block isn't contained within a function. Also, your line "function (OnTriggerEnter)" is a little confusing. You can remove that part and shove the rest into the OnTriggerEnter function.

 function OnTriggerEnter( other : Collider )
 {
     if (other.gameObject.tag == "Dreamshard")
     {
         Dreamshard += 1;
         Debug.Log("A dreamshard was picked up. Total shards = " + Dreamshard);
         Destroy(other.gameObject);
     }
     if (win == true)
     {
         if (other.gameObject.tag == "ExitLab")
         {
             Application.loadedLevel("MainMenu");
         }
     }
 }
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 tanoshimi · May 17, 2015 at 06:38 PM

Please indent your properly. When you do, you'll see that you have tried to define your OnTriggerEnter() function within a if(win == true) {} block.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Scripting error #2! 2 Answers

Incremental game need help 1 Answer

OnCollisionEnter2D not working? 2 Answers

Script error: OnTriggerEnter 1 Answer

Issue with OnTriggerEnter. 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