Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 agununes · Sep 23, 2012 at 01:34 AM · gunbulletsholemix

i need to mix this scripts, gun shoot

I want to mix scripts:

 var prefabBullet:Transform;
 var shootForce:float;
 var shots : int = 0;
 var maxShots : int = 8;
 var shootSound : AudioClip;
 function Update()
 {
 if(Input.GetButtonDown("Fire1") && shots < maxShots)
 {
 var instanceBullet = Instantiate(prefabBullet, transform.position, Quaternion.identity);
 instanceBullet.rigidbody.AddForce(transform.forwar d * shootForce);
 audio.PlayOneShot(shootSound);
 shots++;
 }
 else if (shots >= maxShots && Input.GetKeyDown(KeyCode.R))
 {
 shots = 0;
 }
 }

I like this because you have limit bullets , but with this script i cant delete the bullets(clone) but with this script i can:

 var projectile : Rigidbody;
 var speed = 20;
 
 function Update () {
 
 if ( Input.GetButton ("Fire1")) {
 
 clone = Instantiate(projectile, transform.position, transform.rotation);
 clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));
 
 Destroy (clone.gameObject, 3);
 
 }}


And i need that the bullet make a hole

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
1

Answer by aldonaletto · Sep 23, 2012 at 02:44 AM

This is easy: just call Destroy in the first script, right after creating the bullet:

   ...
   instanceBullet.rigidbody.AddForce(transform.forward * shootForce);
   Destroy(instanceBullet.gameObject, 3);
   ...

About the bullet hole: you must create it when the bullet collides with something. Add a script like this to the bullet prefab:

 var holePrefab: GameObject; // drag the hole prefab here
 
 function OnCollisionEnter(col: Collision){
   Destroy(gameObject); // destroy the bullet
   var contact: ContactPoint = col.contacts[0]; // get the first hit point
   // calculate the hole position in front of the hit point:
   var pos: Vector3 = contact.point + contact.normal * 0.005;
   // find a rotation that aligns the plane with the surface:
   var rot: Quaternion = Quaternion.FromToRotation(Vector3.up, contact.normal);
   // instantiate the hole:
   var hole: GameObject  =  Instantiate(holePrefab, pos, rot);
   // "glue" the hole to the object hit by childing it: 
   hole.transform.parent = col.transform;
   Destroy(hole, 30); // destroy the hole automatically after 30 seconds
 }

The hole prefab itself is a small plane with an appropriate material. Use the Unity's Quad primitive to create a simple plane, set its size and assign to it a material with the Transparent/Cutout/Diffuse shader and the hole texture.

Comment
Add comment · Show 1 · 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 agununes · Sep 23, 2012 at 08:38 PM 0
Share

The first was very useful but the second script (Bullet hole) says: https://fbcdn-sphotos-f-a.akamaihd.net/hphotos-ak-ash3/564330_4661920196121_806735817_n.jpg

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

10 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

Related Questions

How do I make it so that my bullet projectile for my gun does damage? 1 Answer

shooting gun help 0 Answers

My reloading script not working after low bullets 2 Answers

Objects instantiate at prefab location instead of playtime location 1 Answer

Showing a dynamic amount of bullets in a Belt/Magazine/Cylinder 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