2019-06-10 14:28:33 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
2019-06-04 17:20:53 +00:00
|
|
|
using src.Base;
|
2019-06-12 20:27:32 +00:00
|
|
|
using src.Helpers;
|
2019-06-04 17:20:53 +00:00
|
|
|
|
|
|
|
namespace src.Wall
|
|
|
|
{
|
2019-06-10 14:28:33 +00:00
|
|
|
public class DestructibleWall : GameplayComponent, IExplosable
|
2019-06-04 17:20:53 +00:00
|
|
|
{
|
|
|
|
private bool _spawnExit;
|
|
|
|
private bool _spawnUpgrade;
|
2019-06-11 17:01:43 +00:00
|
|
|
public GameObject explosionPrefab;
|
|
|
|
public GameObject exitDoorPrefab;
|
2019-06-04 17:20:53 +00:00
|
|
|
|
|
|
|
public void SpawnsExit()
|
|
|
|
{
|
|
|
|
_spawnExit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SpawnsUpgrade()
|
|
|
|
{
|
|
|
|
_spawnUpgrade = true;
|
|
|
|
}
|
2019-06-05 19:24:19 +00:00
|
|
|
|
|
|
|
public float XCoordinate => transform.position.x;
|
|
|
|
public float YCoordinate => transform.position.y;
|
|
|
|
|
2019-06-11 17:01:43 +00:00
|
|
|
private void BeforeDestroy()
|
2019-06-04 17:20:53 +00:00
|
|
|
{
|
2019-06-11 17:01:43 +00:00
|
|
|
var currentPosition = transform.position;
|
|
|
|
Destroy(GetComponent<SpriteRenderer>());
|
|
|
|
Instantiate(explosionPrefab, currentPosition, Quaternion.identity);
|
2019-06-04 17:20:53 +00:00
|
|
|
if (_spawnExit)
|
|
|
|
{
|
2019-06-12 20:27:32 +00:00
|
|
|
DebugHelper.LogInfo($"Destructible spawned exit {transform.position}");
|
2019-06-11 17:01:43 +00:00
|
|
|
Instantiate(exitDoorPrefab, currentPosition, Quaternion.identity);
|
2019-06-05 19:24:19 +00:00
|
|
|
}
|
|
|
|
else if (_spawnUpgrade)
|
2019-06-04 17:20:53 +00:00
|
|
|
{
|
2019-06-12 20:27:32 +00:00
|
|
|
DebugHelper.LogInfo($"Destructible spawned upgrade {transform.position}");
|
2019-06-11 17:01:43 +00:00
|
|
|
// TODO: Get and instantiate upgrade from manager
|
2019-06-04 17:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-10 14:28:33 +00:00
|
|
|
|
|
|
|
public void onExplosion()
|
|
|
|
{
|
2019-06-12 20:27:32 +00:00
|
|
|
DebugHelper.LogInfo($"Destructible wall hit by explosion {transform.position}");
|
2019-06-11 17:01:43 +00:00
|
|
|
BeforeDestroy();
|
|
|
|
Destroy(gameObject);
|
2019-06-10 14:28:33 +00:00
|
|
|
}
|
2019-06-04 17:20:53 +00:00
|
|
|
}
|
|
|
|
}
|