Hi everyone…I have searched alot but unable to find a solution so plz help.Basically what i am trying to do is as you can see in the simplified script that i have made an array(it have three items an each is parent of its child objects) and then instantiating these items randomly.what i want is that the first instantiate should occur above an object already in the scene but then the second object should instantiate on above the previous instantiated object and the third one above the second instantiate and so on. Now what i think i want is a way to determine if intantiate(if this is not possible then we can put instantiate in a seperate function and check if that happened or no but i dont understand how to put either of these two checks in if condition) have occured or no,that is the condition for if statement,if its yes then i need a reference to the last instantiation that ocurred so i can put it equal to lastRedgeSet.plz help and also suggest a better way of doing this if any`public class Pcg : MonoBehaviour {
public GameObject[] RedgeSets;
private GameObject LastRedgeSet;
public GameObject FixedRedges;
private Object myist;
void Start () {
LastRedgeSet = FixedRedges;
}
void Update () {
// if(instantiate happened or no Condition here){
//LatRedgeSet = (refrence to last instantiated object required here) }
Vector3 LastRedgeSetPos = LastRedgeSet.transform.position;
Vector3 addheight = new Vector3 (0, 5, 0);
if (Input.GetKeyDown (KeyCode.Z)) {
Instantiate (RedgeSets [UnityEngine.Random.Range (0, 3)], LastRedgeSetPos + addheight, Quaternion.identity);
}
}`