I am instantiating my prefab into the scene and looking for an easy way to access it and change this object (size, Sprite renderer...). Is there a way to give cloned objects for example tag or other way to change it direclty?
bird= Instantiate(birdPrefab).GetComponent();
CodePudding user response:
You could store the instantiated object in a variable like you do in your example. But instead of bird = Instantiate(birdPrefab).GetComponent(); you could just do bird = Instantiate(birdPrefab) and later do a bird.GetComponent<>(); to change it's value.
Otherwise if you instantiate multiple gameobjects and you want to edit them all you could give the prefab a certain tag and with FindGameObjectsWithTag("Your Tag") you will get all gameobjects with that tag in a list.
https://docs.unity3d.com/ScriptReference/GameObject.FindGameObjectsWithTag.html