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 goten000023 · Sep 02, 2014 at 10:33 PM · c#javascriptraycastshootingnoob

need help converting gun script from c# to javascript

a user named BMayne answered my question here

he gave this script as a answer to show me a better way to do that kind of shooting

 float currentAmmo = 5.0f;
 float currentReloadTime = 0.0f;
 bool isReloading = false;
  
 const float RELOAD_TIME = 2.0f;
 const int MAX_AMMO = 8; 
  
  
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.R))
     {
         if (currentAmmo != MAX_AMMO && !isReloading) // if we already have max ammo lets leave or if we are already reloading
         {
             isReloading = true; // We are now reloading
             currentReloadTime = RELOAD_TIME; //Set our current load time 
         }
     }
  
     if (isReloading)
         ReloadStep();
     else
         GunStep();
  
  
 }
  
 void GunStep()
 {
     if (currentAmmo <= 0)
         return; //No ammo so we leave.
  
     if (!Input.GetMouseButtonDown(0)) //the '!' means Not. so the mouse button is Not Down 
         return; //We are not firing so we don't need to be here
  
     //We fired our gun so we need to use a bullet 
     currentAmmo--;
  
     //Start our making our raycast
     RaycastHit hit;
     Ray ray = Camera.main.ScreenPointToRay(new Vector3((float)Screen.width * 0.5f, (float)Screen.height * 0.5f, 0.0f));
  
     //Fire the ray and tell anything we hit to apply damage
     if (Physics.Raycast(ray, out hit, 100))
     {
         hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
     }
 }
  
 void ReloadStep()
 {
     currentReloadTime -= Time.deltaTime; //We count down
  
     if( currentReloadTime <= 0.0f )
     {
         isReloading = false;
         currentAmmo = MAX_AMMO;
     }
 }
 

and I use javascript so i was wondering if someone could convert this to javascript so i can understand it better. thanks in advance.

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

1 Reply

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

Answer by kacyesp · Sep 02, 2014 at 10:50 PM

This might help: http://answers.unity3d.com/questions/497764/convert-c-to-js-1.html

If you read through the answer and comments, you'll find a bunch of references for how to do this yourself.

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 goten000023 · Sep 03, 2014 at 02:09 AM 0
Share

thank you so much, this is exactly what i was looking for, now i can convert it myself!!!

avatar image kacyesp · Sep 03, 2014 at 02:18 AM 0
Share

@goten000023 Feel free to accept the answer and possibly upvote it :)

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

having problems with my raycast shooting script 0 Answers

im having trouble with raycast shooting script 0 Answers

musket gun script is not working 3 Answers

Third Person Shooting Script Stopped Working 1 Answer

raycast to object, load wrong script!? 2 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