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 /
  • Help Room /
This question was closed Mar 24, 2016 at 03:53 AM by Dragonnoble for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Dragonnoble · Jan 22, 2016 at 04:39 PM · instantiatemultiple

Is there a simply script edit to spawn more than one rigidbody at a time using the script below?

I am making a fun, sandbox game where the character(in first person) is able to spawn objects from his box. I have most of it figured it out, except I can't figure out how to instantiate more than one object(copies of itself) instead of one object at a time. The script so far:

using UnityEngine; using System.Collections;

public class Spawn : MonoBehaviour {

 public Rigidbody spawnObject;
 
 public float speed = 20;
   
 void Update () {
 
     if (Input.GetButtonDown("Fire1"))
     {
         Rigidbody instantiatedspawnObject = Instantiate(spawnObject, transform.position, transform.rotation) as Rigidbody;
 
         instantiatedspawnObject.velocity = transform.TransformDirection(new Vector3(0, 0,speed));
 
     }
 }
 
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 ShadyProductions · Jan 22, 2016 at 08:05 PM 0
Share

Like constantly instantiate objects while holding fire button down?
Try Input.GetButton("Fire1") ins$$anonymous$$d of GetButtonDown

avatar image Dragonnoble ShadyProductions · Jan 24, 2016 at 01:51 AM 0
Share

$$anonymous$$ore like click once and it instantiates multiple objects at one, but I'll try this and see if I like it better.

avatar image DoubleIsLoveDoubleIsLife · Dec 09, 2016 at 09:28 AM 0
Share

Tons of ways to do this. Use a for loop, a while loop, call a function multiple times.

         for(int i = 0; i < amountoftimeyouwant; i++) {
                  Rigidbody instantiatedspawnObject = Instantiate(spawnObject, transform.position, transform.rotation) as Rigidbody;
          
                  instantiatedspawnObject.velocity = transform.TransformDirection(new Vector3(0, 0,speed));
         }
     

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

instantiate prefab at every gameobject with tag 0 Answers

Spawn in a different and random Spawn point from a list 0 Answers

why does my instantiate sometimes dupe my prefab? 1 Answer

What kind of Void should I use? 1 Answer

How to instantiate prefabs by adding two others? 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