Answer the question
In order to leave comments, you need to log in
How to create object in Unity object?
Hello. There was such a problem that it is impossible to shove noteTile as a child object in the Journal on which the script is hung.
public class Journal : MonoBehaviour
{
List<Note> noteList = new List<Note>();
[SerializeField] GameObject noteTile;
string noteName, noteDescription;
bool nul = true;
void Start ()
{
CheckNotes();
}
void CheckNotes ()
{
if (nul)
{
noteName = "note name";
noteDescription = "note description";
noteList.Add(new Note(noteName,noteDescription));
noteTile.name = noteName;
Instantiate(noteTile,gameObject);
}
}
}
class Note
{
public string name;
public string description;
public Note(string name, string description)
{
this.name = name;
this.description = description;
}
}
Answer the question
In order to leave comments, you need to log in
If noteTile
- this is a reference to an object that is already in the scene, then you do not need to instantiate the object, but simply change the parent
noteTile.transform.parent = parent.transform;
where parent
- this GameObject
is where you want to place it noteTile
. If it is noteTile
not instantiated, then you should first instantiate, and only then set various parameters.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question