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 Saron Nightfury · Apr 17, 2013 at 01:04 AM · javascriptgetcomponentgunammo

I Made a Revolver Script, But It's Saying There is an Error

I made a script, but it keeps saying I have an error on line 20. Here's the error it has: Assets/Revolver Script.js(20,14): BCE0043: Unexpected token: .. .I can't figure out what's wrong with it. Here is the line: var AmmoCount.GetComponent;

Edit Shooting part not by me, but the ammo count and stuff like that are by me. Shooting script link:http://www.unity3dmax.comxa.com/ShootScript.html Here is the script (sorry about that): //the bullet we are shooting must have a rigidbody var Bullet : Transform; //the speed the bullet is shot at var Speed = 16000; //where the bullet spawns (most likely the tip of the gun) var spawnPoint : Transform; //if we shoot like a machinegun or not var RapidFire = false; //if we shoot every click or not var SingleFire = true; //this is only used if rapid fire is set to true private var shooting = false; //RateOfFire private var Counter = Time.deltaTime; var RateOfFire = 0.250000; var AmmoCount = 6; function Update () { var AmmoCount.GetComponent; if button.down.("shoot"); if AmmoCount > 0; getComponent.AmmoCount - 1; //if single fire is set to true if(SingleFire==true){ //we are using the left mouse button to shoot if(Input.GetButtonUp("shoot")){ //we create the bullet var shot =Instantiate(Bullet, spawnPoint.transform.position, Quaternion.identity); //we add the speed shot.rigidbody.AddForce(transform.forward * Speed); } } if(RapidFire ==true){ if(Input.GetButtonDown("shoot")){ shooting=true; } if(Input.GetButtonUp("shoot")){ shooting=false; } if(shooting==true){ Counter += Time.deltaTime; if(RateOfFire < Counter){ var shotRapid =Instantiate(Bullet, spawnPoint.transform.position, Quaternion.identity); //we add the speed shotRapid.rigidbody.AddForce(transform.forward * Speed); Counter=0; } } } } else if AmmoCount < = 0; void; if button.down.("reload"); if AmmoCount = 0; getComponent.AmmoCount + 1; //Reloading Animation 1" else if AmmoCount = 1; getComponent.AmmoCount + 1; //Reloading Animation 2" else if AmmoCount = 2; getComponent.AmmoCount + 1; //Reloading Animation 3" else if AmmoCount = 3; getComponent.AmmoCount + 1; //Reloading Animation 4" else if AmmoCount = 4; getComponent.AmmoCount + 1; //Reloading Animation 5" else if AmmoCount = 5; getComponent.AmmoCount + 1; //Reloading Animation 6" else if AmmoCount = 6; getComponent.AmmoCount + 1; //Reloading Animation 7" } } } } If you tell me how, I will try to straighten it. If not, here is an image: alt text

revolver script.png (49.7 kB)
Comment
Add comment · Show 1
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 iwaldrop · Apr 17, 2013 at 01:36 AM 1
Share

We also need the code. :)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Negagames · Apr 17, 2013 at 01:43 AM

You didn't post the code, but with my minimal knowledge of compilers that means you didn't use the right syntax or symbol. You posted AmmoCount.GetComponent;. That should be phrased:

AmmoCount.GetComponent(The Component you want to get);

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 Dracorat · Apr 18, 2013 at 08:30 PM

Variable names can't contain periods.

I think you wanted something like:

 var ComponentName componentVariable = AmmoCount.GetComponent(ComponentName);

Except that "AmmoCount" can't be right either because you made it an int above that.

Did you want to use the Transform object to get the component? (common)

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 Saron Nightfury · Apr 18, 2013 at 08:33 PM 0
Share

I did that and I got a whole bunch of errors. I am trying to make it recieve the AmmoCount so it can basically check when to not fire and when it needs to reload.

avatar image Dracorat · Apr 18, 2013 at 08:37 PM 0
Share

I just took a deeper look at your code. It's so wrong I don't know where to begin other than to tell you that you should learn to code first.

Here is a great place to start: http://unityscript.com/lessons1/lessons/1_Introduction.html

Once you do this, you should see that there is no such animal (or need for one) as what you just typed.

avatar image Saron Nightfury · Apr 18, 2013 at 08:44 PM 0
Share

Ok thanks. This is my first attempt at scripting in general, besides just editing them.

edit I looked through it and found out what might have been wrong, but i got the same error. reedit putting a picture: alt text

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

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

ammo display javascript 1 Answer

Cannot get script component while the game object has a refered script 1 Answer

an object seemingly cannot access a value in other. 1 Answer

Can someone translate C# to Javascript? 2 Answers

musket gun script is not working 3 Answers


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