Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Steel598 · Jul 12, 2017 at 09:33 PM · bulletclonesgun script

i have too many bullets...

i am using some scripts that i found that make it so I can shoot. It uses a variable that is the ball, and it spawns it to the empty gameobject that shoots it. here is the website I got it from: https://mega.nz/#F!dkklTQiR!WL25e1TKLmhYKQT2RpIXNA (you will have to sign in, i just used blur for fake account though) it lets me shoot, but in the files it gives me two choices: either gives me a certain amount of time I can keep the bullet and it will destroy all the clones with it, or it will keep all the clones and keep the bullet. for ease of use, here is the shoot program that makes the clones: static var ammo = 100; static var maxAmmo = 100; var key : String = "mouse 0"; var bullet : Rigidbody; var speed : float = 1000;

 function Update () {
     if(Input.GetKeyDown(key)){
         if(ammo > 0){
             shoot();
         }
     }
 }
 function shoot(){
     var bullet1 : Rigidbody = Instantiate(bullet, transform.position, transform.rotation);
     bullet1.AddForce(transform.forward * speed);
     ammo --;
 }

I need a way to destroy the clones and keep the main bullet. thanks!

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
1

Answer by Cornelis-de-Jager · Jul 12, 2017 at 09:58 PM

Simply add the following bit to the script:

 float time = 5f; // Time it takes after spawn for bullet to be destroyed
 
 void Start () {
     Destroy (this.gameObject, time)
 }

You can then also destroy the bullet when it collides with an object

 void OnCollisionEnter (Collision other) {
       Destroy (this.gameObject);
 }
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
avatar image
0

Answer by Steel598 · Jul 12, 2017 at 10:05 PM

@Cornelis-de-Jager do I put the float time stuff at function update? thanks for that tidbit though! edit: it also gives me these error messages: Assets/gun script/Unity gun scripts/shoot.js(9,37): UCE0001: ';' expected. Insert a semicolon at the end.

Assets/gun script/Unity gun scripts/shoot.js(6,7): UCE0001: ';' expected. Insert a semicolon at the end.

another edit: fixed one of these errors, but the other one says it needs a semicolon even though it has one. thanks, i got the place too.

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 Cornelis-de-Jager · Jul 12, 2017 at 10:13 PM 0
Share

like it says, I missed a semi-colon. Just add it:

 Destroy (this.gameObject, time);

And the float needs to be outside all functions, but still within the class.

avatar image Cornelis-de-Jager · Jul 12, 2017 at 10:14 PM 0
Share

Oh btw! this should be added to a script that is attached to the bullet ins$$anonymous$$d of the script that actually spans the bullet. Sorry about confusion!!!!

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

69 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 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 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 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

making my gun shoot... 3 Answers

Need Help with Shooting Script c# 5 Answers

How to make a bullet spread 1 Answer

My bullet isn't facing the correct way when I shoot it out of my gun. Help! 0 Answers

Bullets aren't firing / Bullet holes not instantiating correctly 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