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 C Griffin · Jul 09, 2012 at 02:19 PM · gameobjectinstantiatemultiple

Instantiates 2 or more gameObjects on ButtonUp.

Hello again.

My new problem du-jour is perplexing me. I have a script that Instantiates a sphere on ButtonUp to prevent a stream of them from being produced per Will Goldstein's tutorials. The sphere is a Rigidbody and has a force applied to it when it is instantiated to give it forward momentum.

Initially it worked as intended, however it now routinely produces 2- sometimes more- of these prefabs with no discernible force added to them. Instead of moving forward, these 2 (or more up to 8) stack on top of each other like some sadistic snowman. I have no idea why they would do this.

Every once in a while it will correctly produce a single sphere that moves as it should and I feel happy, however lately that has not been the norm. I will include the bit of relevant code below:

shooter is a GameObject variable that I have preloaded with my prefab that I want to shoot.

 function Shoota(){
  
  
  if(Input.GetButtonUp("Fire1")){
  Instantiate(shooter, transform.position, transform.rotation);
  spawned = true;
  }

}

Please know that my oding skills are somewhat lacking, however I will probably understand any answer. Ideally in my final product Player1 will have their turn and then Player2 will have a go, which is why this needs to work correctly. Sorry if this is poorly worded, its early for me and I'm tired as heck.

Thanks Again, -C. Griffin

P.S. The movement that I referenced above is in a script placed on the Shooter prefab that adds a force in the update function until it collides with either the ground or another marble, which then destroys said script. I don't know if this is the correct way to do that, but as I said earlier, "my coding, eet's not so good".

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

Answer by stingman · Jul 09, 2012 at 11:52 PM

your code is lacking some necessary information to be able to answer this. But I figure this will work. Modify your code to use this example:

 var canShoot = true; //set a boolean to determine whether the user can shoot or not... prevents multiple instantiations.
 
 function Update() {
 if (canShoot)
 Shoota();
 }
 
 function Shoota() {
 if (Input.GetButtonUp("Fire1")) {
 Instantiate(shooter, transform.position, transform.rotation);
 spawned = true;
 canShoot = false;
 }
 }
 
 
 // You will need to reset canShoot to "true" if you want to be able to shoot again.  That's easy though and it's more of a preference of where you want to do that.  I'll leave that up to you :)
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Reading XML file 0 Answers

Instantiated Objects not being set at ground/terrain level?(Solved) 1 Answer

Checking Instantiate/Destroy has been called | Checking number of scene GameObjects 1 Answer

Every NetworkViewID is 0? 0 Answers

How to put gameObjects to the list? 4 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