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 sander rolleman · Oct 25, 2014 at 03:24 PM · shootreloadingrocketsunlimited

How to make a reloading time because now i can shoot unlimited

Hello, I have a problem and i think is t not very hard but i can't fix it. Now i can shoot rockets but there is no limit, i can shoot unlimited and that not really realistic :) thanks in advance, Sander

Script:


 using UnityEngine;
 using System.Collections;
 
 public class RocketSpawnSource : MonoBehaviour {
     public GameObject RocketPrefab;
     public static bool rocketShooted;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
 
         if (Input.GetMouseButtonDown(0))
 
         {
             Instantiate(RocketPrefab,transform.position,transform.rotation);
             StartCoroutine("RocketShooted");
 
         }
     }
 }



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
0

Answer by Landern · Oct 25, 2014 at 03:26 PM

You need a cool down of some sort.

  using UnityEngine;
  using System.Collections;
  
  public class RocketSpawnSource : MonoBehaviour {
      public GameObject RocketPrefab;
      public static bool rocketShooted;
      public int RocketCoolDown = 5; // Used to assign in editor and reset the rocketCoolDownCount.
          
      private int rocketCoolDownCount;
          
      // Use this for initialization
      void Start () {
                 rocketCoolDownCount = RocketCoolDown; // initialize the Cool down count.
      }
      
      // Update is called once per frame
      void Update () {
  
          if (Input.GetMouseButtonDown(0))
          {
              if (rocketCoolDownCount > 0)
              {
                  rocketCoolDownCount--;
              }
              else
              {
                  Instantiate(RocketPrefab,transform.position,transform.rotation);
                  StartCoroutine("RocketShooted");
              }
          }
      }
  }

 

In your RocketShooted method that you didn't include here, you need to reset the rocketCoolDownCount to RocketCoolDown.

 // in your RocketShooted method, after shooting
 rocketCoolDownCount = RocketCoolDown;


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 sander rolleman · Oct 27, 2014 at 11:04 PM 0
Share

at first,i appreciate your helpthanks!

but we dont have a RocketShooted method and now i can shoot also unlimited, when i start the game and want to shoot the first rocket, i have to click 5 times and than the first rocket shoot, after that i can shoot unlimited such as in the beginning

avatar image
0

Answer by bubzy · Oct 27, 2014 at 11:07 PM

 float shootDelay = 0.2f;
 float currentDelay; 
 
 void Start()
 {
 currentDelay = Time.time + shootDelay;
 }
 
 void Update () {
  
          if (Input.GetMouseButtonDown(0))
  
          {
            if(Time.time > currentDelay)
              {
              Instantiate(RocketPrefab,transform.position,transform.rotation);
              StartCoroutine("RocketShooted");
              currentDelay = Time.time + shootDelay;
              }
  
          }
      }
 
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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Shoot Script Reload Help 1 Answer

When reloading my gun sounds and the bullets glitch out. 2 Answers

gun wont reload 1 Answer

Shooting and reloading mechanism problem. 1 Answer

Only trigger when in specific animation 2 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