Hey, I made a system to spawn Towers depending on their Type (I have a TowerType enum). It looks like this:
commands.spawn((
SpriteSheetBundle {
texture,
atlas: TextureAtlas {
layout: texture_atlas_layout,
index: animation_indices.first,
},
transform: Transform::from_translation(tower_position).with_scale(tower_scale),
..default()
},
animation_indices,
AnimationTimer(Timer::from_seconds(animation_frame_duration, TimerMode::Repeating)),
Tower {
tower_type: *tower_type,
cooldown: tower_type.cooldown(),
}
));
Now I want to conditionally insert the Component ShouldRotate to it, if tower_type.has_rotation() is true
I tried it by assigning commands.spawn() to a variably let mut tower = commands.spawn($BUNDLE); and then doing
if tower_type.has_rotation() {
tower.insert(ShouldRotate);
}
This however does not work because of rusts borrowing rules.
Can I archive this without copying the entire commands.spawn()?