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 DayyanSisson · Oct 11, 2011 at 03:43 AM · shootingtransform.positionshootfirelaser

Firing System with two Shoot Points

I'm making a space sim, and want a script where I could determine the shoot points in the inspector. It ALMOST works. Here's the firing script:

 var canShoot : boolean = true;
 var projectile : GameObject;
 var secondary : GameObject;
 var fireRate : float = 0.1;
 var secondaryFireRate : float = 3.0;
 private var nextFire : float = 0.0;
 private var nextSecondaryFire : float = 0.0;
 var hasMuzzleFlash : boolean = true;
 var muzzleFlash : GameObject;
 var secondaryMuzzleFlash : GameObject;
 static var bulletsLeft : int = 100000000; ///Infinte = 100000000
 static var missilesLeft : int = 30;
 private var hasFired : boolean = false;
 private var hasFiredSecondary : boolean = false;
 private var bulletsPerShot : float = 1;
 private var missilesPerShot : float = 1;
 private var boosting : boolean = false;
 var shootPointOne : Transform;
 var shootPointTwo : Transform;

 function Update() 
 {
 
  hasFired = false;
     hasFiredSecondary = false;
     
     if(bulletsLeft == 0)
     bulletsPerShot = 0;
     
     if(missilesLeft == 0)
     missilesPerShot = 0;
     
     if(Input.GetKey("space")){
     
     boosting = true;
     }
     else if(fighter){
     
     boosting = false;
     }
     
     
     if(Input.GetButton("Fire1") && Time.time > nextFire && bulletsLeft > 0 && !boosting && canShoot) {
         nextFire = Time.time + fireRate;
         Instantiate (projectile, shootPointOne.position, transform.rotation);
         hasFired = true;
     }
   
     
     if(Input.GetButton("Fire1") && Time.time > nextFire && bulletsLeft > 0 && !boosting && canShoot) {
 
         nextFire = Time.time + fireRate;
         Instantiate (muzzleFlash, shootPointOne.position, transform.rotation); 
 }
 
     if(Input.GetButton("Fire1") && Time.time > nextFire && bulletsLeft > 0 && !boosting && canShoot) {
         nextFire = Time.time + fireRate;
         Instantiate (projectile, shootPointTwo.position, transform.rotation);
         hasFired = true;
     }
   
     
     if(Input.GetButton("Fire1") && Time.time > nextFire && bulletsLeft > 0 && !boosting && canShoot) {
 
         nextFire = Time.time + fireRate;
         Instantiate (muzzleFlash, shootPointTwo.position, transform.rotation); 
 }

It pretty much works, and it shoots in the shoot point. But the second shoot point doesn't work. It shoots at shootPointOne, but it doesn't shoot at shootPointTwo. I don't know why it's not working.

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
Best Answer

Answer by syclamoth · Oct 11, 2011 at 04:18 AM

See all those if statements? Put all of that in one if statement. Then, it won't block the ones at the end!

Comment
Add comment · Show 4 · 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 DayyanSisson · Oct 13, 2011 at 11:04 PM 0
Share

It works, but the problem is, whenever I shoot, the starship starts jerking back and forth. Do you know why it's doing this. There is no rigidbody attached, and even when there was it still did this. It's not the shootPoints or the lasers because even after I took out the shoot points, and it didn't shoot anything, then ship jerked back and forth.

avatar image syclamoth · Oct 14, 2011 at 03:50 AM 0
Share

I only mean the ones to do with shooting. The boost one and all that still have to be separate!

avatar image DayyanSisson · Oct 14, 2011 at 04:43 AM 0
Share

I know that. The boost is in it's own section of if statements, and the shooting is in it's own section. Here's the shooting part now:

 if(Input.GetButton("Fire1") && Time.time > nextFire && bulletsLeft > 0 && !boosting && canShoot) {
         nextFire = Time.time + fireRate;
         Instantiate (primary, shootPointOne.position, transform.rotation);
         Instantiate (primary, shootPointTwo.position, transform.rotation);
         Instantiate (primary, shootPointThree.position, transform.rotation);
         Instantiate (primary, shootPointFour.position, transform.rotation);
         Instantiate (muzzleFlash, shootPointOne.position, transform.rotation);
         Instantiate (muzzleFlash, shootPointTwo.position, transform.rotation);
         Instantiate (muzzleFlash, shootPointThree.position, transform.rotation);
         Instantiate (muzzleFlash, shootPointFour.position, transform.rotation);
         hasFired = true;
     }
 
       if(hasFired) {
         bulletsLeft -= bulletsPerShot;
 }
     
     if(Input.GetButton("Fire2") && Time.time > nextSecondaryFire && missilesLeft > 0 && !boosting && canShoot) {
         nextSecondaryFire = Time.time + secondaryFireRate;
         Instantiate (secondary, missileShootPoint.position, transform.rotation);
         Instantiate (secondary, missileShootPointTwo.position, transform.rotation);
         Instantiate (secondary$$anonymous$$uzzleFlash, missileShootPoint.position, transform.rotation);
         Instantiate (secondary$$anonymous$$uzzleFlash, missileShootPointTwo.position, transform.rotation);  
         hasFiredSecondary = true;
     }    
     if(hasFiredSecondary) {
         missilesLeft -= missilesPerShot;
 }

See. It's in it's own if statement, away from the rest. I still have no idea why it's jerking.

avatar image DayyanSisson · Oct 31, 2011 at 12:29 AM 0
Share

Never$$anonymous$$d, it doesn't do that in the build. Thanks.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

how do i stop automatic firing? 3 Answers

Problem with firing laser in direction of camera 1 Answer

Hold Button Shooting 3 Answers

Audio when I shoot 3 Answers

How to avoid speed change in bullets while moving? 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