2019-06-02 10:00:00 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2019-06-08 12:25:09 +00:00
|
|
|
|
public class BombController : MonoBehaviour, IExplosable
|
2019-06-02 10:00:00 +00:00
|
|
|
|
{
|
|
|
|
|
public GameObject explosionPrefab;
|
|
|
|
|
|
|
|
|
|
BombStatsUtil bombStatsUtil = BombStatsUtil.Instance;
|
|
|
|
|
bool exploded = false;
|
|
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
Invoke("Explode", bombStatsUtil.Timer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Explode()
|
|
|
|
|
{
|
|
|
|
|
Instantiate(explosionPrefab, transform.position, Quaternion.identity);
|
|
|
|
|
|
2019-06-08 12:25:09 +00:00
|
|
|
|
GetComponent<SpriteRenderer>().enabled = false;
|
2019-06-02 10:00:00 +00:00
|
|
|
|
transform.Find("2DCollider").gameObject.SetActive(false);
|
|
|
|
|
|
2019-06-08 12:25:09 +00:00
|
|
|
|
StartCoroutine(CreateExplosions(Vector3.down));
|
|
|
|
|
StartCoroutine(CreateExplosions(Vector3.left));
|
|
|
|
|
StartCoroutine(CreateExplosions(Vector3.up));
|
|
|
|
|
StartCoroutine(CreateExplosions(Vector3.right));
|
|
|
|
|
|
2019-06-02 10:00:00 +00:00
|
|
|
|
exploded = true;
|
2019-06-08 12:25:09 +00:00
|
|
|
|
Destroy(gameObject, 0.3f);
|
|
|
|
|
//GameObject bombObject = Instantiate(explosionPrefab, transform.position, Quaternion.identity);
|
|
|
|
|
//bombObject.GetComponent<Explosion>().Explode(transform.position);
|
2019-06-02 10:00:00 +00:00
|
|
|
|
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-08 12:25:09 +00:00
|
|
|
|
private IEnumerator CreateExplosions(Vector3 direction)
|
2019-06-02 10:00:00 +00:00
|
|
|
|
{
|
|
|
|
|
for (int i = 1; i < bombStatsUtil.Power; i++)
|
|
|
|
|
{
|
2019-06-08 12:25:09 +00:00
|
|
|
|
RaycastHit2D hit = Physics2D.Raycast(new Vector2(transform.position.x, transform.position.y), direction, i, 1 << 8);
|
2019-06-02 10:00:00 +00:00
|
|
|
|
if (!hit.collider)
|
|
|
|
|
{
|
|
|
|
|
Instantiate(explosionPrefab, transform.position + (i * direction), explosionPrefab.transform.rotation);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-06-08 12:25:09 +00:00
|
|
|
|
Debug.Log("Collided with something");
|
2019-06-02 10:00:00 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-08 12:25:09 +00:00
|
|
|
|
yield return new WaitForSeconds(0.05f);
|
|
|
|
|
|
2019-06-02 10:00:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnTriggerEnter2D(Collider2D other)
|
|
|
|
|
{
|
|
|
|
|
if (!exploded && other.CompareTag("Explosion"))
|
|
|
|
|
{
|
2019-06-08 12:25:09 +00:00
|
|
|
|
onExplosion();
|
2019-06-02 10:00:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-08 12:25:09 +00:00
|
|
|
|
|
|
|
|
|
public void onExplosion()
|
|
|
|
|
{
|
|
|
|
|
//In caz ca o bomba loveste bomba, dam cancel la explozie sa nu explodeze twice si o explodam automagic
|
|
|
|
|
CancelInvoke("Explode");
|
|
|
|
|
Explode();
|
|
|
|
|
}
|
2019-06-02 10:00:00 +00:00
|
|
|
|
}
|