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 Ben 20 · Feb 02, 2011 at 07:15 PM · instantiatewhile

This segment of code is causing problems

if(Input.GetButtonDown("Fire1") && !reloading && shot == "spread") { var i : int = 3;

         while(i > 0)
         {
             clone = Instantiate(bullet, transform.position, transform.rotation);
             i--;
         }
         ammo--;
     }

If I remove the while loop the bullets shoot straight like normal. But I want to do a spread shot and this method is causing the bullets to spiral off the screen. Any ideas on how to do a spread shot would be appreciated.

Comment
Add comment · Show 3
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 johan-skold · Feb 02, 2011 at 07:27 PM 0
Share

I would assume the bullets themselves have a script that causes them to go forward? That script is probably what's causing the spiraling as there's nothing in this snippet that could cause such an issue.

avatar image Proclyon · Feb 02, 2011 at 10:37 PM 0
Share

You can use the &! operator ins$$anonymous$$d of doing && !someVar

avatar image johan-skold · Feb 08, 2011 at 11:51 AM 0
Share

&! isn't an operator, it's actually two. See the comments at the bottom of this page: http://msdn.microsoft.com/en-us/library/6a71f45d(v=vs.80).aspx

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Borgo · Feb 02, 2011 at 07:46 PM

Your script are creating 3 bullets instances at same time, position and rotation.
If your bullets have colliders this can be a problem because they will collide thenselves
Try to remove colliders if they have.

Looking at your script, I assume that the acceleration of the bullets is not in this script. Maybe it's in a script attached in the bullets, like Johan posted.

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
avatar image
0

Answer by Ben 20 · Feb 02, 2011 at 08:15 PM

Ok the code segment that controls the acceleration is in another script that is attached to a bullet prefab.

var speed = 10.0; //Can be adjusted if needed

function Start() //Affects bullet accuracy { var acc : int = Random.Range(0, 6); transform.Rotate(0, acc, 0);
}

function Update () { var translation = speed; translation *= Time.deltaTime; transform.Translate(0, 0, translation); }

function OnCollisionEnter(hit : Collision) { if(hit.collider.gameObject.CompareTag("Wall") || hit.collider.gameObject.CompareTag("Enemy") ) Destroy(gameObject); }

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

No one has followed this question yet.

Related Questions

Checking if object intersects? 1 Answer

While loop freezing Unity 3 Answers

Instantiate Code Issue 0 Answers

While Loop Not Assigning Array 1 Answer

Repetitive task within a fixed timeframe? 0 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