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 deadlycrow · Feb 14, 2014 at 12:33 AM · javascriptdelayhorrorgunfire

More refined gunshot system

Hi, iam developing an horror FPS game, in this moment iam scripting the gunshot system, buti think my code is too complicated, iam starting with this languages (JS, CS)

these are my codes:

1)--- Damage system with Raycast

     var Effect : Transform;
     var TheDammage = 30;
     
     function Start() {
     }
     
     function Update () {
     
     GunShot();
         
     }
     function GunShot (){
     
     
         var hit : RaycastHit;
         var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
         
         if (Input.GetButtonDown("Fire1"))
         {    yield WaitForSeconds(0.25);
             if (Physics.Raycast (ray, hit, 105))
             {
             
                 var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
                 Destroy(particleClone.gameObject, 0.5);
                 hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
             }
         }
     
     }

2)--- The bullet spawner(just visual effect)

 var Bullet : GameObject;
 var BulletSpawn : Transform;
 
 function Start () {
 
 }
 
 function Update () {
 
 bulletshown();
     
 }
 function bulletshown (){
 
 if(Input.GetButtonDown("Fire1")){
     yield WaitForSeconds(0.02);
     Instantiate(Bullet ,BulletSpawn.transform.position , BulletSpawn.transform.rotation);
     yield WaitForSeconds(1.0);
 
     }
 
 }

3)--- The bullet itself (visual effect only)

 var BulletSpeed = 0.4;
 
 function Start () {
 }
 
 function Update () {
 
     transform.Translate(Vector3.left * BulletSpeed);
     }

(if you are wondering why i put the vector3 on the LEFT, that is because the bullet model which im using is rotated 90 degrees, so i rotated the Bullet spawner 90 degrees to the right, and that is why i put the vector3 on the left instead of FORWARD)

So my question is: can anyone help me to simplify the code? i mean, make a only one JS for this GUN thing? so when i try to put the animation will be more easier to fit with the whole gunshot script instead of modifyng 3 different codes at the same time... whatever, thats what i think... ANOTHER THING!! the "YIELD WAITFORSECONDS" code doesn't work properly, my objetive is delaying the gunshots(because the main weapon is a revolver, and you know... revolver like magnum, a heavy rough shot) and actually the revolver fires more like a damn UZI... ahaha just kidding, but these delays that i put just are delaying the mouse clicks so more than a delayed shot looks like a LAG shot if you know what i mean..

so that it is my problem... and sorry for my lame english :P hopefuly anyone help me, and this for the ones who have similar troubles too(and read this forums) :P

greetings :)

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 getyour411 · Feb 14, 2014 at 12:34 AM 0
Share

New users with lower karma have to get their questions approved by a moderator before they show up. Please do not post the same question over and over again - be patient and your question will be looked over and approved.

0 Replies

· Add your reply
  • Sort: 

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

18 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 avatar image avatar image avatar image avatar image

Related Questions

Inspector Assigned Variables Not In Both Scenes 1 Answer

Using Time with OnGUI Help 2 Answers

rigidbody2D only jump while grounded 1 Answer

How do you make a trig object? 0 Answers

How can I make a gui with buttons pop up in javasript? 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