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
1
Question by deadfroggy · Dec 31, 2012 at 04:42 AM · fpsshootinggun

Shooting script problem.

Ok. Im not bad with scripting and whatever. But this is my script. I Keep Getting these few errors. The Errors are: (Filename: Assets/Scripts/shooting.js Line: 35)

Assets/Scripts/shooting.js(36,25): BCE0043: Unexpected token: :.

(Filename: Assets/Scripts/shooting.js Line: 36)

Assets/Scripts/shooting.js(36,26): UCE0001: ';' expected. Insert a semicolon at the end.

(Filename: Assets/Scripts/shooting.js Line: 36)

When i put them in it says That it doesn't need to be there.I would Appreciate any help.

pragma strict

ar projectile : Rigidbody; var speed : float; var Spawn : Transform; var Nextshoot : float; var Projectiledelete : float; var Reloadtime : float = 2; var AmmoInMag : float = 50; static var AmmoLeft : float; private var CanFire = true; function Start () { AmmoLeft = AmmoInMag;

}

function Update () { if (AmmoLeft == 0) { Reload(); } if (AmmoLeft < 0){ AmmoLeft = 0; } if (CanFire == true){ if (Input.GetButton("Fire1")){ if(AmmoLeft > 0){ BroadcastMessage("FireAnim"); if (Time.time>Nextshoot){ Nextshoot=Time.time+0.2; var instantiatedProjectile : Rigidbody = Instantiate(projectile,Spawn.position, Spawn.rotation ); instantiatedProjectile.velocity = transform.TransformDirection( Vector3( speed, 0, 0 ) ); AmmoLeft -= 1; audio.Play(); } function Reload (){ CanFire == false; BroadcastMessage("ReloadAnim"); yield WaitForSeconds(Reloadtime); CanFire == true; }

if(Time.time>Projectiledelete){ Projectiledelete=Time.time+0.5; Destroy(GameObject.Find("Projectile(Clone)")); }

} } }

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

Answer by clunk47 · Dec 31, 2012 at 06:47 AM

You cannot put a function inside of a function. You had function Reload() inside of function Update(). You also only use double equals sign "==" when you're asking if something is equal to something else. To SET the boolean, you only use 1 equals sign (you had Canfire == true instead of Canfire = true. You did use this correctly when using an if statement - if(Canfire == true)... You can also say if(Canfire), and if you want to check if it is false, use an exclamation point "!" in front of the statement, ! meaning NOT. So you could say if(!Canfire) instead of if(Canfire == false). Here is your fixed code :)

 #pragma strict

 var projectile : Rigidbody;
 var speed : float; 
 var Spawn : Transform; 
 var Nextshoot : float; 
 var Projectiledelete : float; 
 var Reloadtime : float = 2; 
 var AmmoInMag : float = 50;
 static var AmmoLeft : float;
 private var CanFire = true; 
 
 function Start () 
 { 
     AmmoLeft = AmmoInMag;
 }
 
 function Update () 
 { 
     if (AmmoLeft == 0) 
     { 
         Reload();
     }
     
     if (AmmoLeft < 0)
     { 
         AmmoLeft = 0; 
     } 
     
     if (CanFire)
     { 
         if (Input.GetButton("Fire1"))
         { 
         
             if(AmmoLeft > 0)
             { 
                 BroadcastMessage("FireAnim");
             
                 if (Time.time>Nextshoot)
                 { 
                     Nextshoot=Time.time+0.2; 
                     var instantiatedProjectile : Rigidbody = Instantiate(projectile,Spawn.position, Spawn.rotation ); 
                     instantiatedProjectile.velocity = transform.TransformDirection( Vector3( speed, 0, 0 ) ); AmmoLeft -= 1; audio.Play(); 
                 } 
                 
                 if(Time.time>Projectiledelete)
                 {
                     Projectiledelete=Time.time+0.5; Destroy(GameObject.Find("Projectile(Clone)")); 
                 }
             } 
         } 
     }
 }
 
 function Reload()
 { 
     CanFire = false; 
     BroadcastMessage("ReloadAnim"); 
     yield WaitForSeconds(Reloadtime); 
     CanFire = true; 
 }
Comment
Add comment · Show 2 · 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 deadfroggy · Dec 31, 2012 at 07:10 AM 0
Share

Thank You So $$anonymous$$uch.

avatar image clunk47 · Dec 31, 2012 at 03:14 PM 1
Share

Did this help? If it has resolved your issue, if you could please accept the answer (Check $$anonymous$$ark) and / or vote it up (Thumbs up). I've voted up your question for it being a good one, so now you have over 15 karma, which means you have the ability to vote up posts :) Hope this helped.

avatar image
0

Answer by deadfroggy · Jan 01, 2013 at 12:52 PM

Yes it helped majorly thankyou.

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

9 People are following this question.

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

Related Questions

How do I destroy a gameobject after 5 seconds 2 Answers

Advanced FPS shooting 1 Answer

How to add sound to gun shot script 4 Answers

How can I shoot bullets that you can aim with the crosshair? 1 Answer

FPS aim marker Question 0 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