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 CalebSong · Aug 26, 2018 at 02:14 AM · projectiles

Shooting bullets with Instantiate function

Hey guys. I'm trying to shoot a bullet, and I somehow managed to do it. But now I added a shop script, and it doesn't shoot anything. Do you see anything wrong? The script itself doesn't have an error.

public class BulletGenerator : MonoBehaviour { public GameObject BulletPrefab; public static BulletGenerator instance; private ShopScript shop; private List stat = new List(); public int capacity = 15; public int mags = 12; public float FireRate = 10; public float lastfired; void Awake() { if (instance == null) { instance = this; }

 }
 void Start () {
     shop = ShopScript.instance;
     stat = shop.enabled;
 }
 
 // Update is called once per frame
 void Update ()
 {
     NewMethod();
     if (stat[1] == true) {
         mags += 7;
         stat[1] = false;
         stat[1] = shop.enabled[1];
     }
 }

 private void NewMethod()
 {
     if (stat[6] == true)
     {
         if (Input.GetMouseButton(0))
         {
             if (Time.time - lastfired > 1 / FireRate)
             {
                 lastfired = Time.time;
                 shootFunction();
             }
         }
     }
     else
     {
         if (Input.GetMouseButtonDown(0))
         {
             shootFunction();
         }
     }
 }

 IEnumerator shootFunction() {
     if (Input.GetMouseButtonDown(0))
     {
         if (capacity < 1)
         {
             yield return new WaitForSeconds(2f);
             if (stat[2] == true)
             {
                 capacity = 30;
             }
             else {
                 capacity = 15;
             }
             mags -= 1;
         }
         else {
             if (mags < 0)
             {

             }
             else {
                 Instantiate(BulletPrefab, transform.position, transform.rotation);
                 capacity -= 1;
             }
         }

     }
 }

}

Comment
Add comment · Show 1
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 eses · Aug 26, 2018 at 08:19 AM 0
Share

Hi @CalebSong - You code is not formatted properly, first lines are outside code formatting...

What is the condition "stat[6] == true"?
Asking because else part looks a bit strange.

You are calling coroutine like it is a method - "shootFunction();" ins$$anonymous$$d of using StartCoroutine.

You are querying input the second time in your "shootFunction" coroutine?

In your coroutine, you are once again doing some "stat[2] == true" check? only in else part you are shooting something...

0 Replies

· Add your reply
  • Sort: 

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

87 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 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 Can I Make a Projectile Move? 2 Answers

Issue with instantiation delay that pooling doesn't fix 0 Answers

How can I fire bullets at mouse position 1 Answer

Power-Ups increasing projectile stats 1 Answer

Projectiles too fast for Physics 3 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