Answer the question
In order to leave comments, you need to log in
How to work with created objects in code?
Good day, friends.
There is a code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Gameplay : MonoBehaviour {
string Word;
public GameObject PrefabCharCell;
public GameObject tempCell;
public Transform GridCellPos;
void Start ()
{
Word = "Meet";
foreach (char ch in Word.ToUpper().ToCharArray())
{
tempCell = Instantiate(PrefabCharCell);
tempCell.transform.SetParent(GridCellPos,false);
}
}
}
Answer the question
In order to leave comments, you need to log in
Pass selected objects to other methods and functions.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Gameplay : MonoBehaviour {
string Word;
public GameObject PrefabCharCell;
public GameObject tempCell;
public Transform GridCellPos;
void SomeMethod(GameObject tempCell){
}
void Start ()
{
Word = "Meet";
foreach (char ch in Word.ToUpper().ToCharArray())
{
tempCell = Instantiate(PrefabCharCell);
tempCell.transform.SetParent(GridCellPos,false);
SomeMethod(tempCell);
}
}
}
Why pass selected objects to other methods? it won't solve the problem in any way.
You need to push them into the Sheet, in the loop where you have the creation.
Then you already work with the sheet and you will have both the first and second object, you will search by index and that's it
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question