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 /
This question was closed Feb 05, 2013 at 08:31 PM by Eric5h5 for the following reason:

Question is off-topic or not relevant

avatar image
0
Question by TASNO · Feb 05, 2013 at 06:53 PM · raycastprefabbulletgun

Gun Script

Can I please have a gun script that shoots a prefab. The gun script I have is a Raycast.

 var Range : float = 1000; //Range of gun
 var Force : float = 1000; //Force of bullet on objects
 var Clips : int = 20; //Number of clips
 var BulletPerClip : int = 60; // Bullets in a clip
 var ReloadTime : float = 3.3; //Time taken to reload
 var BulletsLeft : int = 0;
 var ShootTimer : float = 0;
 var ShootCooler : float = 0.9; //Cooldown time after every shot
 var Damage : int = 10; //Damage done to object by the gun
 
 function Start () {
     BulletsLeft = BulletsLeft;
 }
 
 function Update () {
     if( ShootTimer > 0){
         ShootTimer -= Time.deltaTime;
     }
     if( ShootTimer < 0){
         ShootTimer = 0;
     }
     if(Input.GetKey(KeyCode.Q)){
         if( ShootTimer == 0){
             RayShoot();
             ShootTimer = ShootCooler;
         }
     }
 
 }
 
 function RayShoot (){
     var Hit : RaycastHit;
     var DirectionRay = transform.TransformDirection(Vector3.forward);
     Debug.DrawRay(transform.position, DirectionRay * Range, Color.blue);
     if(Physics.Raycast(transform.position, DirectionRay, Hit, Range)){
         if(Hit.rigidbody){
             Hit.rigidbody.AddForceAtPosition( DirectionRay * Force, Hit.point);
             Hit.collider.SendMessageUpwards("ApplyDamage", Damage , SendMessageOptions.DontRequireReceiver);
         }
     }
     BulletsLeft --;
     if( BulletsLeft < 0){
         BulletsLeft = 0;
     }
     if(BulletsLeft == 0){
         Reload();
     }
 }
 
 function Reload (){
     yield WaitForSeconds( ReloadTime);
     if ( Clips > 0){
         BulletsLeft = BulletPerClip;
     }
 }


Please Reply ASAP.

TASNO :D

Comment
Add comment · Show 5
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 TASNO · Feb 05, 2013 at 07:00 PM 0
Share

Why did I get a thumbs down :(

avatar image LightSource · Feb 05, 2013 at 08:06 PM 2
Share

You don't ask for scripts out of the blue, take some time to learn or watch a tutorial.

avatar image Eric5h5 · Feb 05, 2013 at 08:32 PM 2
Share

This isn't a site to ask people to write scripts for you, it's for specific development questions.

avatar image EliteMossy · Apr 02, 2013 at 05:01 PM 1
Share

@TASNO: I would also learn some manners.

avatar image logang · Apr 02, 2013 at 05:09 PM 0
Share

hey TASNO whats your email?

0 Replies

  • Sort: 

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

How do I create bullet hole for my gun? 0 Answers

Use transform.LookAt with Raycast with a delayed bullet? 1 Answer

How do shoot a bullet when the right button is clicked? 1 Answer

2D Sending Object From One Place To Mouse Position. 1 Answer

Control amount of bullets 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