- Home /
10 Objects, One Script, 1 ID,Multiple Objects One script one int?
I have an integer on a single script that is assigned to 10 different objects, I want each object to have a ID of a different number between 1 and 10. Thanks,Hi, I am trying to assign and Id for 10 different objects that all have the same script assigned to them, I want the ID to be a number between 1 and 10 so each object has a number between 1 and 10 and none of them have the same ID. Thanks.
Answer by bdubbert · Nov 17, 2021 at 10:53 PM
A static int should do the trick
public class MyClass : MonoBehaviour {
private static int _id = 0;
public int id;
void Awake(){
id = ++_id;
}
}
Your answer
Follow this Question
Related Questions
Rotating a gameobject using integers 3 Answers
Confining / Constraining an object transform trajectory to a mesh 1 Answer
How to snap object to terrain after already placed in scene? 3 Answers
Why does my editor only render game objects that are not in the default layer? 1 Answer
what should I take note when making a game character? 0 Answers