bugs attack

This commit is contained in:
artem 2024-02-25 12:35:10 +03:00
parent 062daf6743
commit 1f03c20237
3 changed files with 5 additions and 4 deletions

View File

@ -187,10 +187,10 @@ impl Enemy {
if !self.fight {
return;
}
let index = ctx.scene.graph.try_get_script_index_of::<Player>(self.player_handle).unwrap();
match ctx
.scene
.graph
.try_get_script_of_mut::<Player>(self.player_handle)
.scene
.graph.try_get_mut(self.player_handle).and_then(|node| node.try_get_script_mut::<Player>(index))
{
Some(script) => {
if script.get_health() <= 0.0 {

View File

@ -358,10 +358,11 @@ impl Player {
parent = Some(d.parent());
}
if let Some(d) = parent {
let index = context.scene.graph.try_get_script_index_of::<Enemy>(d).unwrap();
match context
.scene
.graph
.try_get_script_of_mut::<Enemy>(d)
.try_get_mut(d).and_then(|node| node.try_get_script_mut::<Enemy>(index))
{
Some(script) => {
script.take_damage(&self.damage);