I’m instantiating two capsules with force. When I make one a prefab that has the other as a child, One of the capsules sort of shakes on the spot while the other shoots forward.
I read on another thread that I should use a for loop. If that’s the best solution, could you show me how you would use it?
Well you didn’t tell us what language you use, so I’ll give an example in C# and another in JS(UnityScript). In this example I have a public GameObject where you will need to drag a prefab from your assets folder into the slot on this component once it’s attached to a gameObject in your scene. This simply creates two clones of your prefab and instantiates them in the same position. No need for a for() statement.
//C-Sharp Example.cs
using System.Collections;
using UnityEngine;
public class Example : MonoBehaviour
{
public GameObject prefab;
void Awake()
{
GameObject go1 = (GameObject)Instantiate(prefab, Vector3.zero, Quaternion.identity);
GameObject go2 = (GameObject)Instantiate(prefab, Vector3.zero, Quaternion.identity);
}
}
//JavaScript(UnityScript) example
#pragma strict
var prefab : GameObject;
function Awake()
{
var go1 = Instantiate(prefab, Vector3.zero, Quaternion.identity);
var go2 = Instantiate(prefab, Vector3.zero, Quaternion.identity);
}