- Home /
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:
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);
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)
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.
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.
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: