The question is answered, right answer was accepted
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));
}
}
Like constantly instantiate objects while holding fire button down?
Try Input.GetButton("Fire1")
ins$$anonymous$$d of GetButtonDown
$$anonymous$$ore like click once and it instantiates multiple objects at one, but I'll try this and see if I like it better.
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));
}