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 EliteHedgehog56 · Aug 20, 2017 at 01:55 AM · shootingammopickups

limited ammo and ammo pickups

In my splitscreen shooter instead of having to pick up weapons, each plaer has all the weaons at the start but so far all the guns have unlimited ammo, I am using an automatic rigidbody shooting script that is added to an empty prefab child in each weapon prefab called 'firing point', I want to change my shooting script to have a limited supply of held ammo. So basically when a weapon's ammo has depleated I want it to disable the firing point child so the player cant shoot it anymore and then when the player comes into contact with an ammo pickup I want to tell the ammo pickup to send a message to the shooting script to add ammo to the weapon and re-enable the firing point child so the player can use the weapon again.

here's my script

RequireComponent(AudioSource); var audioSource: AudioSource; var Projectile : Rigidbody; var ProjectileSpeed : int = 10; var FireRate : float = 10; // The number of bullets fired per second var lastfired : float; // The value of Time.time at the last firing moment var gunshot : AudioClip; var muzzleflash :Transform;

function Start() { audioSource = GetComponent.(); }

function Update () { if (Input.GetAxis("Fire1")>0f) { if (Time.time - lastfired > 1 / FireRate) { lastfired = Time.time; var clone : Rigidbody; clone = Instantiate(Projectile, transform.position, transform.rotation); clone.velocity = transform.TransformDirection (Vector3.forward * ProjectileSpeed); audioSource.PlayOneShot(gunshot, 0.7F); Instantiate (muzzleflash,transform.position,transform.rotation); } } }

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

Answer by AbominationGames · Aug 20, 2017 at 05:51 AM

You technically don't need to disable the firing point. You can create a boolean canShoot and set it to false or true. Then you can just toggle the boolean, this will also allow for you to add to your script later, (weapon jams, reloading, hit, object interference, etc).

PSEUDO CODE: ammo = 0; canFire = false;

Update: if ammo >= 0 canFire = true

if (canFire) { if(Input.GetAxis("Fire1") && Time.time - lastfired > 1 / FireRate) { Shoot();

Shoot() { InstantiateBuller(); ResetShotTimer(); }

So this way you never have to disable your fire point you just can't shoot whenever your bool is set to false. This allows you to make it to where if you're falling, or in the water later you can't shoot. It will allow you to expand later on this way much easier than having to deal with disabling the objects.

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 EliteHedgehog56 · Oct 08, 2017 at 08:47 AM 0
Share

@gamemonk

what I want to do is make it similar to turok rage wars on n64, where the player starts with some ammo for their first weapon (for my case the pistol)

that boolean looks like what I need but coudl you please add it into my script in my answer because I don't quite know where to put your code snippets

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

how do i make this advance fire system for my player!!! 1 Answer

Repeatedly Getting Errors On An Ammo Script 3 Answers

Display Ammo Count Above Player 1 Answer

Gun with limited ammo? 1 Answer

Projectile Firing/Gun script 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