• 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
2
Question by Mihai · Oct 29, 2010 at 04:17 PM · errorsyntax-erroruce0001

Problem:Insert a semicolon at the end.

i am making a fps game and i have a weapon script.The problem is that unity is telling me to insert a semicolon at te end ; line(50,15),but i have already put a semicolon there!

var sound : AudioClip; var bulletSpeed = 100; var projectile : Rigidbody; var bullets = 30; var totalBullets = 60; var reloadTime = 3;

function Update () { Fire(); Reload(); }

function Fire () {

if(bullets > 0) { // Ctrl was pressed, launch a projectile if (Input.GetButtonDown("Fire1")) { // Instantiate the projectile at the position and rotation of this transform var clone : Rigidbody; clone = Instantiate(projectile, transform.position, transform.rotation);

     // Give the cloned object an initial velocity along the current 
     // object's Z axis
        clone.velocity = transform.TransformDirection (Vector3.forward * bulletSpeed);
        AudioSource.PlayClipAtPoint(sound, transform.position, 1);
     //take a bullet of our clip if firing       
        bullets -=1;
        GameObject.Find("bullet_count").guiText.text = ""+totalBullets;
 }

}

}

function Reload() { if(Input.GetButtonDown("Reload"))
{ yield WaitForSeconds (reloadTime) ;

 if(totalBullets > 0)
 {
    int transfer = 30 - bullets;

    if (transfer > totalBullets) 
    { 
       transfer = totalBullets; 
    }
    bullets += transfer;
    totalBullets -= transfer;

 }

 }

}

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
1
Best Answer

Answer by skovacs1 · Oct 29, 2010 at 04:41 PM

Your indentation is all over the place. Also, you shouldn't use GameObject.Find, especially in an Update. Whether you use GameObject.Find or not, you should store a reference to the GameObject or Component at start so you won't have to Find it again and again.

Your problem is that you have mixed your syntax. For most of your code, you are using javascript, but at the line int transfer = 30 - bullets; you are incorrectly declaring the variable.

Here's a cleaner and corrected version:

var sound : AudioClip; var bulletSpeed : float = 100.0f; var projectile : Rigidbody; var bullets : int = 30; var bulletsPerClip : int = 30; var totalBullets : int = 60; var reloadTime : float = 3.0f; private var bulletCounter : GuiText;

function Start() { bulletCounter = GameObject.FindWithTag("Counter").guiText; }

function Update() { Fire(); Reload(); }

function Fire () { if(bullets > 0 && Input.GetButtonDown("Fire1")) { // Instantiate the projectile at the position // and rotation of this transform var clone : Rigidbody = Instantiate(projectile, transform.position, transform.rotation);

     // Give the cloned object an initial velocity along its Z axis
     clone.velocity = clone.forward * bulletSpeed;
     AudioSource.PlayClipAtPoint(sound, transform.position, 1);
     //take a bullet off our clip if firing
     bullets--;

     //You really shouldn't use GameObject.Find - it's slow
     //Tag your object and use GameObject.FindWithTag() in stead
     //Better still, since the object doesn't change store a reference to it
     //GameObject.Find("bullet_count").guiText.text = ""+totalBullets;
     bulletCounter.text = ""+totalBullets;
 }

}

function Reload() { if(Input.GetButtonDown("Reload")) { yield WaitForSeconds(reloadTime); if(totalBullets > 0) { var transfer : int = bulletsPerClip - bullets;

         if(transfer > totalBullets) transfer = totalBullets; 

         bullets += transfer;
         totalBullets -= transfer;
     }
 }

}

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
1

Answer by elbon96 · Oct 29, 2010 at 04:40 PM

You have an extra '}' at the end of your code. Remove it and your script should work.

This problem often crops up when your nesting is broken, so whenever it says that and there is a semicolen on the end of your line, check your nesting and make sure it is correct.

Comment
Add comment · Show 3 · 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 skovacs1 · Oct 29, 2010 at 04:42 PM 0
Share

Actually the braces are fine.

avatar image elbon96 · Oct 29, 2010 at 04:51 PM 0
Share

Really? I found an extra using UniSciTE. Hmm.

avatar image elbon96 · Oct 29, 2010 at 05:20 PM 0
Share

Oops, I found it. It was my mistake.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Lerpz tutorial multiple errors.HELP!!!! 4 Answers

Scripting Error when drawing texture to custom window; What am I doing wrong? 1 Answer

Limit rotation for a statue puzzle 1 Answer

Semicolon? WHAT? HELP ME! 1 Answer

Collision Detector script 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