• 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 /
  • Help Room /
avatar image
0
Question by overlordyigit1 · Jun 01, 2016 at 06:06 AM · multipleboatcannoncannonball

shooting multiple cannons with delay

hey,im trying to shot from broadside.i have script in empty gameobject that shot and reload but if i use the script multiple gun,when i shoot all the ball goes same time. i wanna make shot cannons with order (like shot all cannons in 2 second with in random time each other) alt text

unity.png (10.0 kB)
Comment
Add comment · Show 2
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 Guhanesh · Jun 01, 2016 at 06:10 AM 0
Share

share your script.

avatar image overlordyigit1 Guhanesh · Jun 01, 2016 at 12:58 PM 0
Share
  var $$anonymous$$axAmmo =  1;
  var Ammo = $$anonymous$$axAmmo;
  var Bullets = 15;
   
  var Bullet : GameObject;
  var FirePoint : GameObject;
   
  private var timer = 0.0;
  var reloadTime = 2.0;
   
  var Fire : String = "$$anonymous$$usketFire";
  var reloading : boolean;
   
  function Start () 
  {
 
  }
   
  function Update () 
  {    
     if(Ammo > 0 && Input.Get$$anonymous$$ouseButtonDown(1) && Fire == "$$anonymous$$usketFire")
        {
                          
                  FireOneBullet();   
        }
      
      else if(Input.Get$$anonymous$$ey("r"))
      {
          Reload();
   
      }
      else if(reloading) {
          if(timer<reloadTime)
          {
              timer+=Time.deltaTime;
          }
          else
              timer=0.0; 
   
          if(timer>=reloadTime)
          {
              Ammo ++;
              Bullets --;
              timer=0.0;
              reloading = false;
          } 
      }
  }
   
  function FireOneBullet ()
  {var projectile = Instantiate(Bullet,transform.position,transform.rotation);projectile.GetComponent.<Rigidbody>().AddForce(transform.right * 10000);//cannon's x axisPhysics.IgnoreCollision(projectile.collider, collider);
     
 
    //  var Bullet = Instantiate(Bullet, FirePoint.transform.position, transform.rotation);
      Ammo --;
       if(Ammo < $$anonymous$$axAmmo && Bullets > 0)
      { 
          reloading = true;
      }
  }
   
  function Reload ()
   
  {
      if(Ammo < $$anonymous$$axAmmo && Bullets > 0)
      { 
          reloading = true;
      }
  }
 

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Guhanesh · Jun 01, 2016 at 02:35 PM

add yield WaitForSeconds (Random.Range(0.0f,0.5f)); before bullet instantiation script.

  function FireOneBullet ()
   {
   yield WaitForSeconds (Random.Range(0.0f,0.5f));
   var projectile = Instantiate(Bullet,transform.position,transform.rotation);projectile.GetComponent.<Rigidbody>().AddForce(transform.right * 1000);//cannon's x axisPhysics.IgnoreCollision(projectile.collider, collider);
      
  
     //  var Bullet = Instantiate(Bullet, FirePoint.transform.position, transform.rotation);
       Ammo --;
        if(Ammo < MaxAmmo && Bullets > 0)
       { 
           reloading = true;
       }
   }
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 overlordyigit1 · Jun 01, 2016 at 02:52 PM 0
Share

it works ,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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

cannon wont fire on vertical axis! 0 Answers

Cannons wont move on the vertical axis 0 Answers

How to shoot cannon ball in 2d? 0 Answers

Find Number Multiple within Range 0 Answers

GUI Text showing even if the 'if' statement is not met 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