You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.1 KiB
60 lines
1.1 KiB
using Player; |
|
using UnityEngine; |
|
|
|
namespace Ai |
|
{ |
|
public class BlowUpEnemy : TargetingEnemy |
|
{ |
|
[SerializeField] private GameObject _blowSibling; |
|
[SerializeField] private int _count; |
|
[SerializeField] private int _stuck; |
|
[SerializeField] private float _scale; |
|
|
|
private bool _dead; |
|
|
|
protected int Stuck |
|
{ |
|
set |
|
{ |
|
_stuck = value; |
|
} |
|
} |
|
|
|
protected override void Init() |
|
{ |
|
base.Init(); |
|
var body = GetComponent<Body>(); |
|
if (body != null) |
|
{ |
|
body.DeathEvent += OnDeath; |
|
} |
|
} |
|
|
|
private void OnDeath() |
|
{ |
|
if (_stuck <= 0 || _dead) |
|
return; |
|
|
|
_dead = true; |
|
|
|
for (int i = 0; i < _count; i++) |
|
{ |
|
var sib = Instantiate(_blowSibling); |
|
sib.transform.position = transform.position; |
|
var blow = sib.GetComponent<BlowUpEnemy>(); |
|
|
|
var lockObj = blow.transform.GetComponentInChildren<Lock>(true); |
|
if (lockObj != null) |
|
Destroy(lockObj.gameObject); |
|
|
|
if (blow != null) |
|
{ |
|
blow._dead = false; |
|
blow.Stuck = _stuck - 1; |
|
} |
|
|
|
blow.transform.localScale = transform.localScale * _scale; |
|
} |
|
} |
|
} |
|
}
|
|
|