How to create 3 clones with Instantiate at the same time
I'm new to Unity and I've been trying to make a shotgun which shoots like a cone. It was working fine at the beginning, but then somehow i broke it. I'm trying to instantiate 3 bullets, and trying to get the rigidbody of them. But when i try to instantiate 3 times, the other 2 don't clone my gameobject. They just get the first gameobject that's been cloned. I also tried with for loop, but it just didn't work. Here's the way i tried:
spread = Random.Range(-0.2f, 0.2f);
GameObject bullet = Instantiate(bulletPrefab, new Vector3(firePoint.position.x + spread, firePoint.position.y + spread), firePoint.rotation);
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
rb.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);
GameObject bullet1 = Instantiate(bulletPrefab, new Vector3(firePointL.position.x + spread, firePointL.position.y + spread), firePointL.rotation);
Rigidbody2D rb1 = bullet1.GetComponent<Rigidbody2D>();
rb1.AddForce(firePointL.up * bulletForce, ForceMode2D.Impulse);
GameObject bullet2 = Instantiate(bulletPrefab, new Vector3(firePointR.position.x + spread, firePointR.position.y + spread), firePointR.rotation);
Rigidbody2D rb2 = bullet2.GetComponent<Rigidbody2D>();
rb2.AddForce(firePointR.up * bulletForce, ForceMode2D.Impulse);
Your answer
Follow this Question
Related Questions
Add Clones of GameObject to List(array) 0 Answers
instantiate within function without clones 0 Answers
[2D] Instantiate() duplicates former instances 1 Answer
Instantiate problem, spawning too many clones, then cloning the clones! help! 0 Answers
Object being flung off course as soon as it is touching clone of floor 0 Answers