Closed DotNaos closed 1 year ago
// check if component already exists, if so, overwrite it
for (int i = 0; i < components.size(); i++) {
Component existingComponent = components.get(i);
if (existingComponent.getClass().equals(c.getClass())) {
components.set(i, c);
c.gameObject = this;
return;
}
}
Oder:
// Ignorieren
for (Component component : components) {
if (component.getClass() == c.getClass()) {
System.out.println("Error: Component already exists");
return;
}
}
Programm stürzt ab, wenn einem GameObjekt mehrmals die gleiche Komponente hinzugefügt wird.