- Home /
How to set component ID when adding it to the inspector?
Here's the issue I'm trying to solve:
I have a scene with several text components all over the place. I need to set the text for each of these components through a JSON file.
I'm thinking of adding a script to each object with a text component. This script will hold an ID, so the JSON can give me the correct text for each element based on its ID.
The thing is, I don't want to assign this ID manually every time I add this component to a game object. Instead, whenever I add this component to a game object, I want it to 'generate' an ID automatically.
For example, the first time I add the component to a game object, its ID will be 1. The next time I add this component to another game object, the ID will be 2 and so on.
Any idea on how to approach this is very welcome! Thanks!
Your answer
Follow this Question
Related Questions
How am I Randomize my id in json file. 1 Answer
Instantiate ID 2 Answers
Play Services Plugin Google ID doesn't update 0 Answers
How to (de) serialize unity references at runtime? 3 Answers